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

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?

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

@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;
--
Paige Miller

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

@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;
--
Paige Miller
Phil_NZ
Barite | Level 11

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 ?

Thank you for your help, have a fabulous and productive day! I am a novice today, but someday when I accumulate enough knowledge, I can help others in my capacity.
Amir
PROC Star

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: 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
  • 3 replies
  • 625 views
  • 2 likes
  • 4 in conversation