Hello I have this data with four variables A, B, C D that I want to make it one variable A. THe data is as such.
A B C D
1 1 1 .
2 1 . 1
. 2 1 .
. . 2 .
. . . 3
I want to create this data with one variable call A as above
F
1
2
2
3
The variable A B C D are in order and F takes the first number. If all are missing, F will be missing otherwise F takes the first value from the variable A, B, C, D.
The coalesce() function will pick the first non-missing value.
data sample;
input A B C D;
F=coalesce(a,b,c,d);
datalines;
1 1 1 .
2 1 . 1
. 2 1 .
. . 2 .
. . . 3
;
Actually F is: F
F
1
2
2
2
3
The coalesce() function will pick the first non-missing value.
data sample;
input A B C D;
F=coalesce(a,b,c,d);
datalines;
1 1 1 .
2 1 . 1
. 2 1 .
. . 2 .
. . . 3
;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.