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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

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