Have -
id | num1 | num2 | num3 |
1 | 101 | 102 | 103 |
data d1;
input id num1 num2 num3;
datalines;
1 101 102 103
;
run;
Want -
id | num_list |
1 | 101 |
1 | 102 |
1 | 103 |
Incase either of num1, num2, num3 is null then I don't want their entries in the dataset. For example - If num3 is null then dataset should be -
id | num_list |
1 | 101 |
1 | 102 |
Thanks in advance 🙂
Easiest thing to do is simply delete the unwanted rows from the output.
Run PROC TRANSPOSE with the following in the code
by id;
@shubham_d wrote:
Hey! Deleting unwanted rows is fine. But how would I transpose keeping the ID same & creating a new column for this transpose? Basically the dataset of Want
You probably need to make more test data that actually demonstrates the issues you are having (or are worried about).
If you want the re-transposed data to end up in the same variable names then you need to either keep the _NAME_ variable that PROC TRANSPOSE generates (or something that can be used to re-create it) to use in the ID statement of PROC TRANSPOSE.
proc transpose data=have out=TALL(where=(not missing(col1)) ;
by id;
var var1-var3 ;
run;
proc tranpose data=TALL out=WIDE(drop=_name_);
by id;
id _name_;
var col1;
run;
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.