4/22/2008
conditional processing ( if )
example(general if statement)
data family ;
infile datalines dlm=',' missover;
input fname:$20. rship age sex occup income dollar5.;
format income dollar5.;
datalines;
kaya,1,50,0,1,$1500
kaya,2,45,1,2
kaya,3,30,0,1,$2000
sahin,1,60,0,2
sahin,2,50,1,1,$1750
sahin,3,15,1,0,
run;
proc print data=family; run;
data incomeytl;
set family ;
incomeytl=income*1.2;
run;
proc print data=incomeytl; run;
data job;
set family;
if occup eq 1 then status='working';
else status='not working';
run;
proc print data=job; run;
example(length statement)
data job;
set family;
length status $ 20;
if occup eq 1 then status='working';
else if occup=2 or occup=0 then status='not working';
run;
proc print data=job; run;
example(do and end)
data job_status;
set family;
length status $ 20;
if occup eq 1 then status='working';
else do
status='not working';
income=0;
end;
run;
proc print data=job_status; run;
example (multiple if else statement)
data job_status;
set family;
length status $ 20;
if occup eq 1 then status='working';
else if occup=2 then do
status='not working';
income=0;
end;
else if occup= 0 then do
status ='student';
income=0;
end;
run;
proc print data=job_status; run;
example (more than one output dataset)
data working not_working student;
set family;
if occup=0 then output student;
else if occup=1 then output working;
else if occup=2 output not_working;
run;
proc print data=not_working; run;
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment