I am using an array to create a variable I need - variable A.
When I do this, I need to keep certain variables B C D E F G, so I can have them in my final data file.
All of these are character vars except G (numeric var)
However, when I create this file with the array - these extra variables are repeating to fill in blanks - Since new variable A repeats for each ID. The missing in this file are okay. All I need is for the data from these extra variables to be in the first row of the ID, not all of them. Could I add something to the array to make this happen? Or is there any other way I can do this after the data want is created? Thank you.
Data want (keep= ID A B C D E F G);
set have;
array _pres {*} pres: ;
do A=1 to dim(_pres);
if _pres{A}>0 then output;
end;
run;
What I am getting:
ID A B C D E F G
1 2 descript1 . descript3 descript4 . 1
1 9 descript1 . descript3 descript4 . 1
1 12 descript1 . descript3 descript4 . 1
2 10 . descript2 . descript4 descript5 .
2 5 . descript2 . descritp4 descript5 .
3 11 . . descript3 . . .
3 20 . . descript3 . . .
3 33 . . descript3 . . .
what I need:
ID A B C D E F G
1 2 descript1 . descript3 descript4 . 1
1 9 . . . . . .
1 12 . . . . . .
2 10 . descript2 . descript4 descript5 .
2 5 . . . . . .
3 11 . . descript3 . . . .
3 20 . . . . . . .
3 33 . . . . . . .
Data want (keep= ID A B C D E F G);
set have;
by ID;
if not first.id then call missing(B, C, D, E, F, G);
run;
Data want (keep= ID A B C D E F G);
set have;
by ID;
if not first.id then call missing(B, C, D, E, F, G);
run;
Try this:
Data want (keep= ID A B C D E F G);
set have;
by id;
if not first.id then call missing(b,c,d,e,f);
run;
If that's not it, then please provide your original data (in your data set named HAVE) as SAS data step code (instructions).
Thank you. That is it.
Sorry. I got the error because I didn't add the commas. I meant to edit my answer but it took awhile to get through. Thank you!
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 lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.