DATA Step, Macro, Functions and more

IF statement - create a new variable using if statement

Accepted Solution Solved
Reply
Contributor
Posts: 71
Accepted Solution

IF statement - create a new variable using if statement

[ Edited ]

I want to update var1 with the next available var2,3 or 4 value?

 

 

Have:

Var1 var2 var3 var4

1        .      1       1

.        .       .        2

2       1      1       .

.         1      .       .

 

Want :

Var1 var2 var3 var4

1        .      1       1

2      .       .        2

2       2      2       .

1        1      .       .

 

Thanks


Accepted Solutions
Solution
‎07-15-2016 02:16 PM
Trusted Advisor
Posts: 1,228

Re: IF statement - create a new variable using if statement

Hi,

 

Please try this.

 

data want;
set have;
Var1=coalesce(var1,var2,var3,var4);
run;

View solution in original post


All Replies
Solution
‎07-15-2016 02:16 PM
Trusted Advisor
Posts: 1,228

Re: IF statement - create a new variable using if statement

Hi,

 

Please try this.

 

data want;
set have;
Var1=coalesce(var1,var2,var3,var4);
run;

Contributor
Posts: 71

Re: IF statement - create a new variable using if statement

Thank you - it worked !!!
Super Contributor
Posts: 298

Re: IF statement - create a new variable using if statement

It looks that the solution provided to you gets  Var3 in the 4-th observation to 2. I guess I am doing something wrong.

☑ This topic is solved.

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

Discussion stats
  • 3 replies
  • 284 views
  • 0 likes
  • 3 in conversation