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!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.