How to use Conditional Statement in SAS

Demo Program 1:

Title "Demo for Conditional Statement";
data new;
infile cards;
input id name $ class;
put "This is to check the execution in the LOG window:"_all_;
cards;
100 Sanaul 12
101 John   12
103 Greg   11
104 Raj    11
105 Adam   10
106 Ron    9
;
run;
proc print;
run;
data out1 out2 out3;
set new;
if class=12 then output out1;
if class=11 then output out2;
else output out3;
run;
proc print data=out1;
run;
proc print data=out2;
run;
proc print data=out3;
run;

Demo Program 2:

data new;
infile cards;
input id name$;
put "PDV:"_all_;
if id eq 1 then class= 10;
else if id eq 2 then class= 11;
else class= 9;
cards;
1 Sanaul
2 John
1 Rohan
3 Greg
2 Harry
4 Ron
;
run;
proc sort data=new;
by id;
run;
proc print;
run;


Demo Program 3:

data new;
infile cards;
input id name$;
put "PDV:"_all_;
if id <= 2 then class=10;
else if id gt 3 then class=11;
else class= 12;
cards;
1 Sanaul
2 John
1 Rohan
3 Greg
2 Harry
4 Ron
;
run;
proc sort data=new;
by id;
run;
proc print;
run;

Comments

comments

Sanaul

I am having more than 5+ years of experience in SAS Programming and Analysis. But I love to write that's why I am a freelancer writer. So that I can share my experience by working part time as a blogger. I used to travel and explore more and more. Please see my various articles about travel and tourism here

Leave a Reply

Your email address will not be published. Required fields are marked *

9 − seven =

Time limit is exhausted. Please reload CAPTCHA.