BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
LarissaW
Fluorite | Level 6

1.png

my data looks like this now

2.png

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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;

View solution in original post

7 REPLIES 7
Cynthia_sas
SAS Super FREQ
Hi:
PROC REPORT could generate the table you show. I am confused over whether you want a report table, a graph image or an transposed dataset?
Cynthia
LarissaW
Fluorite | Level 6

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

ballardw
Super User

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).

 

 

LarissaW
Fluorite | Level 6

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

Kurt_Bremser
Super User

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;
LarissaW
Fluorite | Level 6
Thank you!
Ksharp
Super User
/*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;

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

How to Concatenate Values

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 252 views
  • 1 like
  • 5 in conversation