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

Hi,

 

I have this dataset with two columns, the first column is the name of the actual variables and the second column is the value for that field.  I want to transpose it but I am really bad with transpose.  I will appreciate some help.

 

This is what I have:

The first column, 'FieldNames,' has the name of the variables I want.  The second column, 'FieldValues,' has the actual values for the fields in the first column.  As you can see, each record for each person is every four obs.

FieldNames FieldValues
Name John
Height 72
Weight 190
Age 44
Name Suzzy
Height 59
Weight 125
Age 40
Name Stephanie
Height 60
Weight 135
Age 30
Name Brenda
Height 59
Weight 136
Age 47

 

 

This is how I need to have the data:

Name Height Weight Age
John 72 190 44
Suzzy 59 125 40
Stephanie 60 135 30
Brenda 59 136 47

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
A_Kh
Lapis Lazuli | Level 10

If you use proc transpose, do it twice. First transpose by Fieldnames, the second time use Fieldnames as ID. You can align variable orders in data or proc steps later.

 proc sort data=have; 
         by fieldnames;
 run; 
 proc transpose data=have out=have1;
	 var fieldvalues;
	 by fieldnames;
 run; 
 proc transpose data=have1 out=want (drop=_:);
	 var col:;
	 id fieldnames;
 run; 

 

View solution in original post

1 REPLY 1
A_Kh
Lapis Lazuli | Level 10

If you use proc transpose, do it twice. First transpose by Fieldnames, the second time use Fieldnames as ID. You can align variable orders in data or proc steps later.

 proc sort data=have; 
         by fieldnames;
 run; 
 proc transpose data=have out=have1;
	 var fieldvalues;
	 by fieldnames;
 run; 
 proc transpose data=have1 out=want (drop=_:);
	 var col:;
	 id fieldnames;
 run; 

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 319 views
  • 1 like
  • 2 in conversation