Solved
Contributor
Posts: 70

# 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:

Thanks for any clue...

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

## 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;

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

## 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
Posts: 8

## 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.