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
;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.