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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.