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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 601 views
  • 2 likes
  • 4 in conversation