my data looks like this now
I'm wondering if is there a way that I could transfer the 'Length' variable into a corresponding table with x-axis "Type' and y-axis 'ID'?
Thank you!
You erroneously posted this in the Graphics community, do you got some misleading answers. I moved this to Programming.
Use PROC TRANSPOSE:
proc transpose
data=have
out=want (rename=(_name_=type col1=length))
;
by id;
var type:;
run;
Hi, I want a transposed dataset. The problem for me now is that I want to merge two datasets, but one of them contains multiple observations under the same ID, like what shows in the first table. Since both type and length are the required variables I want to use in the merged new dataset and they are corresponded, I'm trying to find a way that is able to combine them together. For example, since I have three categories of Type in the first table, I want to make three new variables: 'Type 1', 'Type 2' and 'Type 3'; and under each type, I want to put in the corresponding 'Length' number
It is not clear which is your starting data and which is the one that you want.
If you want to graph anything that first appearance of data is likely much nicer in the long run.
Proc sgplot data=have; scatter x=type y=id / group=length; run;
For example will create a scatter plot with a different marker/color combination for each value of length. Many values of length can make the graph busy with multiple symbol/colors.
Proc sgpanel data=have; panelby length; scatter x=type y=id; run;
The above will create a graph with separate panels for values of length (though lots of values may require some additional options to look nice).
Hi, I want a transposed dataset. The problem for me now is that I want to merge two datasets, but one of them contains multiple observations under the same ID, like what shows in the first table. Since both type and length are the required variables I want to use in the merged new dataset and they are corresponded, I'm trying to find a way that is able to combine them together. For example, since I have three categories of Type in the first table, I want to make three new variables: 'Type 1', 'Type 2' and 'Type 3'; and under each type, I want to put in the corresponding 'Length' number
You erroneously posted this in the Graphics community, do you got some misleading answers. I moved this to Programming.
Use PROC TRANSPOSE:
proc transpose
data=have
out=want (rename=(_name_=type col1=length))
;
by id;
var type:;
run;
/*Simple PROC TRANSPOSE*/
data have;
input id type length;
cards;
1 1 3
1 2 1
1 3 2
2 1 2
2 3 3
3 1 1
;
proc transpose data=have out=temp(drop=_name_) prefix=Type;
by id ;
var length;
id type;
run;
proc stdize data=temp out=want reponly missing=0;
run;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.