Hi,
I have a Dataset
ID A B C
1 10 11 12
2 20 21 22
3 30 31 32
I want the dataset same ID grouped like below :
ID want
1 10
1 11
1 12
2 20
2 21
2 22
3 30
3 31
3 32
Can I do this in SAS? thanks
Did you try a PROC TRANSPOSE?
Transposing data tutorials:
Wide to Long:
https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-wide-to-long-using-proc-transpose/
https://stats.idre.ucla.edu/sas/modules/reshaping-data-wide-to-long-using-a-data-step/
Example:
data have; input ID A B C; datalines; 1 10 11 12 2 20 21 22 3 30 31 32 ; proc transpose data=have out=want (drop=_name_); by id; var a b c; run;
Since this uses a by Variable by default your data has to be sorted by the ID variable.
You did not indicate what the name of the new variable would be. The default from the procedure is Col1.
Note: if you have repeats of values of the ID variable you will get multiple Col after transpose. So if you have multiples of the same ID you need to show an example of that data what you expect the result to be for that example.
You can also reshape data with arrays.
data wide;
input ID A B C;
datalines;
1 10 11 12
2 20 21 22
3 30 31 32
;
proc print;
run;
data long2;
set wide;
array items(3) A B C;
do i=1 to dim(items);
want=items[i];
output;
end;
drop i A B C;
run;
https://stats.oarc.ucla.edu/sas/modules/reshaping-data-wide-to-long-using-a-data-step/
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.