Hi everyone,
I have two question please answer them:
1. Is it true that we can't use if statement in all SAS Procedures? Are there some procedures in which we can use if statement, If yes then please name some of them.
2. Can we use if statement in Proc sql? If yes, then please give me a small example.
Thanks,
Ramanuj
No you can't use IF statements in all procs.
I think you're intending to refer to WHERE statements.
AFAIK you can use it all procs.
WHERE is a clause available in SQL.
You cannot use if statement in proc sql.
No you can't use IF statements in all procs.
I think you're intending to refer to WHERE statements.
AFAIK you can use it all procs.
WHERE is a clause available in SQL.
You cannot use if statement in proc sql.
Hi @Ramanuj_Khatri,
Answers:
WHERE statements should work in all procs. The main exception is PROC SQL which has its own WHERE clause as part of statements like SELECT, DELETE or UPDATE.
An actual IF/THEN statement is general NOT available in PROCS. There are some procs that allow you to provide snippets of code that will support IF/THEN statements.
In PROC SQL the type of logic you would use in an IF/THEN statement you would normally code using CASE instead.
So in a data step you could write:
if sex= 1 then gender='Female';
else if sex=2 then gender='Male';
else gender='Unknown;
In PROC SQL you would write:
case when sex=1 then 'Male'
when sex=2 then 'Female'
else 'Unknown'
end as Gender
You can use IF in Proc FCMP (which makes functions calleable in a datastep), Proc Template (in defining some options inside diferent types of templates) , In compute blocks in Proc Report.
I'm sure there are other places but I don't have every SAS module available.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.