BookmarkSubscribeRSS Feed
deleted_user
Not applicable
I'm having some difficulty with a proc transpose.

I want the id field to appear in my new output dataset in ascending order.

i.e.

accno year variable

123 2007 10
123 2006 20
124 2007 30
124 2005 10
124 2006 20

and I want to transpose it to:

2005 2006 2007
123 20 10
124 10 20 30

but the transpose is putting the columns in a different order. Is there an easy way to sort this without me creating new datastep/sql to re-order the columns post-creation?

ta
4 REPLIES 4
Bill
Quartz | Level 8
and the proc transpose code that you used was ...
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
SAS assigns transposed column names as the data is encountered. So you must sort your input data in the desired sequence ahead of the PROC TRANSPOSE execution -- however since you must use a BY statement with your PROC TRANSPOSE code, then you must also coded the NOSORTED option on the BY statement with PROC TRANSPOSE so that SAS will not complain that the data is not in sorted order (based on the BY variable list).

Scott Barry
SBBWorks, Inc.
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
After running a test and reading the DOC, I now see that coding the NOTSORTED option with the sample data sorted by YEAR will result in multiple observations for the BY statement variable list since related observations are not contiguous.

As we have discussed previously, why do you need to have the variables (stored internally) in numeric sequence?

Scott Barry
SBBWorks, Inc.
Flip
Fluorite | Level 6
SAS creates the columns in the order they are encountered. Since you have no obs for 2005 for the first accno it will be created last. You could create an obs with variable = . for 2005 then sort prior to execution.

Easier is to simply specify the order to display the columns and not worry about the internal order.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 4 replies
  • 740 views
  • 0 likes
  • 4 in conversation