BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Ramanuj_Khatri
Obsidian | Level 7

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

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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.  

View solution in original post

5 REPLIES 5
Reeza
Super User

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.  

FreelanceReinh
Jade | Level 19

Hi @Ramanuj_Khatri,

 

Answers:

  1. Examples of procedures which allow the use of an IF statement (in a certain way) include PROC PHREG, PROC GENMOD, PROC NLMIXED, PROC MCMC, PROC GLIMMIX and some other statistical procedures as well as PROC FCMP.
  2. No, an IF statement is not valid in PROC SQL. If you want to perform, e.g., conditional assignments in PROC SQL, please provide details on your problem.
Tom
Super User Tom
Super User

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
Ramanuj_Khatri
Obsidian | Level 7
Thanks Tom, for detailed answer.
ballardw
Super User

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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 4478 views
  • 4 likes
  • 5 in conversation