BookmarkSubscribeRSS Feed
DavidPhillips2
Rhodochrosite | Level 12

I’m looking at proc transpose.  After I use it I’m looking at making a minor update.  Is there a proc to reverse transpose?  I’d like to keep all the same column names and column lengths.

9 REPLIES 9
ballardw
Super User

A concrete example of the start data and the transpose used would help.

Often a set created by transpose can be transposed back if keep the _name_ and _label_ from the first transpose and then use those as the ID and IDLABEL variables on the second transpose.

novinosrin
Tourmaline | Level 20

Nice question. Will this illustration help? I'm learning too. I'll await better examples with you 🙂

 

 

data have;

input col1 & $ col2 dollar5.;

datalines;

Cost 1     $100

Cost 2     $200

Cost 3     $300

;

/*long to wide*/

proc transpose data=have out=wide ;

    id col1;

    var col2;

run;

/*wide to long*/

proc transpose data=wide out=long ;

    id _name_;  

run;

Reeza
Super User

PROC TRANSPOSE goes in both directions. 

 

DavidPhillips2
Rhodochrosite | Level 12

Thanks for the good news.  Is there a transpose all columns option?

art297
Opal | Level 21

Yes, there is a reverse proc transpose, but it will likely destroy you column widths and possibly even variable types. An alternative is to create separate files for all of your transposed variables, and then merge them back together after making your corrections.

 

Art, CEO, AnalystFinder.com

 

DavidPhillips2
Rhodochrosite | Level 12

Given the advice in this thread, it sounds like it would be a lot of work to transpose a table with 100 variables and transpose it back.  It looks like the column names and lengths would be weird after putting it back.

Reeza
Super User

You could force it. I think the names would likely translate back directly but the lengths may be iffy.

 

Assuming you were starting off from a specific format you could create a table like that, using LIKE via SQL and then insert the transposed data. Though if you had that, why do this in the first place 🙂

Rick_SAS
SAS Super FREQ

The techniques you are looking for can be searched for with the terms

transpose "long to wide" data sas

and

transpose "wide to long" data sas

 

There are many, many solutions, including the %MAKEWIDE and %MAKELONG macros.

 

art297
Opal | Level 21

My response is only about 5 months late, but take a look at: https://communities.sas.com/t5/SAS-Communities-Library/How-to-untranspose-a-wide-file/ta-p/425467

 

Your post motivated us to write and publish a macro to solve the problem

 

Art, CEO, AnalystFinder.com

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 9 replies
  • 11683 views
  • 4 likes
  • 6 in conversation