Hi all,
I am new to SAS, I have a question about if then else clause.
I have a variable name s26. I want to set up if s26 is higher than 0 and s26 ne. then fcf=1
If s26 is lower than 0 and s26 ne. then fcf=0.
Could you please suggest to me how to code it?
@ResoluteCarbon wrote:
Hi all,
I am new to SAS, I have a question about if then else clause.
I have a variable name s26. I want to set up if s26 is higher than 0 and s26 ne. then fcf=1
If s26 is lower than 0 and s26 ne. then fcf=0.
Could you please suggest to me how to code it?
The code is essentially what you wrote, except you use > or < symbols
if s26 > 0 and s26 ne . then fcf=1;
else if s26 < 0 and s26 ne . then fcf=0;
A simplification because if s26 > 0 then it has to be not equal to missing
if s26 > 0 then fcf=1;
else if s26 < 0 and s26 ne . then fcf=0;
@ResoluteCarbon wrote:
Hi all,
I am new to SAS, I have a question about if then else clause.
I have a variable name s26. I want to set up if s26 is higher than 0 and s26 ne. then fcf=1
If s26 is lower than 0 and s26 ne. then fcf=0.
Could you please suggest to me how to code it?
The code is essentially what you wrote, except you use > or < symbols
if s26 > 0 and s26 ne . then fcf=1;
else if s26 < 0 and s26 ne . then fcf=0;
A simplification because if s26 > 0 then it has to be not equal to missing
if s26 > 0 then fcf=1;
else if s26 < 0 and s26 ne . then fcf=0;
Hi @PaigeMiller
It looks like that we do not need the condition s26=. at the code
if s26 > 0 and s26 ne . then fcf=1;
because . is the smallest obs in the dataset, isn't it ?
Hi @ResoluteCarbon ,
Further to what @PaigeMiller has said, I recommend you also consider what the logic should do if s26 = 0, for example, flag an error condition or include this possibility in one of the branches of the if statement.
Kind regards,
Amir.
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.