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.

CFC_SAS_Communities_400x225.jpgCFC_SAS_Communities_400x225.jpg

Call for content now open!

It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.

Submit your proposal →

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
  • 1497 views
  • 2 likes
  • 4 in conversation