DATA Step, Macro, Functions and more

If condition

Accepted Solution Solved
Reply
Contributor
Posts: 69
Accepted Solution

If condition

Hello

 

It looks easy and i still do not know what is my mistake.

 

I want to create a new variable named FFOM. This variable will get value if founder (dummy variable 1/0) or secthird  (dummy variable 1/0) is 1 and FOWNFF (countinous variable) >0.

 

This is my code:

data Y210517; set sasuser.y2;
ffom = if founder eq 1 or secthird eq 1 and fownff gt 0 then fownff;
run;

 

The log I got is:

SAS 2105.png

 

Thanks for any clue...

 

 

 


Accepted Solutions
Solution
‎05-21-2017 04:08 AM
Super User
Posts: 17,829

Re: If condition

Are you mixing up CASE and IF statements? 

 

If youre assigning variables using THEN put the assignment at the end rather than at the beginning. 

 

If <condition> then ffom = downfall;

Else ffom = other variable;

View solution in original post


All Replies
Solution
‎05-21-2017 04:08 AM
Super User
Posts: 17,829

Re: If condition

Are you mixing up CASE and IF statements? 

 

If youre assigning variables using THEN put the assignment at the end rather than at the beginning. 

 

If <condition> then ffom = downfall;

Else ffom = other variable;

Valued Guide
Posts: 765

Re: If condition

[ Edited ]

Hi, another idea ... 

 

 

data y2;
input founder secthird fownff @@;
datalines;
0 0 0 1 0 0 1 1 0 0 0 9 1 0 9 1 1 9
;

 

data y210517;

set y2;
ffom = (founder | secthird) * fownff;
run;

 

DATA SET: y210517

founder secthird fownff ffom

0       0        0      0 
1       0        0      0
1       1        0      0
0       0        9      0
1       0        9      9
1       1        9      9

 

 

Occasional Contributor fy1
Occasional Contributor
Posts: 5

Re: If condition

Mike's idea is logically clear. 

 

or similar one like following in SAS. your statement is actually ambiguous.

 

_ffom = (founder eq 1 or secthird eq 1 and fownff gt 0 );

 

ffom=_ffom*fownff;

 

simple is best.  

 

cheers.

 

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 176 views
  • 3 likes
  • 4 in conversation