Proc Transpose Question

Accepted Solution Solved
Reply
Regular Contributor
Posts: 173
Accepted Solution

Proc Transpose Question

Hello Everyone,

I would like to transpose a one-row dataset which containts over 1000 columns.  proc transpose seems to transpose only the numeric columns.  I have read that i need to use VAR to define all character columns in order to transpose them.  I have over 1000 columns so i was hoping to find a better way to transpose every column in the dataset.  Below is the code i used.  cust_data has 1023 variables.  cust_data1 has 851 observations.  172 variables did not get transposed.

Thank you very much for you input ! Smiley Happy

proc transpose data= cust_data out=cust_data1;

run;


Accepted Solutions
Solution
‎11-15-2012 02:42 PM
PROC Star
Posts: 7,363

Re: Proc Transpose Question

Why not use the _all_ keyword?  e.g.:

proc transpose data= cust_data out=cust_data1;

  var _all_;

run;

View solution in original post


All Replies
Solution
‎11-15-2012 02:42 PM
PROC Star
Posts: 7,363

Re: Proc Transpose Question

Why not use the _all_ keyword?  e.g.:

proc transpose data= cust_data out=cust_data1;

  var _all_;

run;

Regular Contributor
Posts: 173

Re: Proc Transpose Question

Thank you Arthur!  that worked beautifully Smiley Happy

Respected Advisor
Posts: 4,651

Re: Proc Transpose Question

I didn't even try! I learn new things every day! Thanks Art.

PG

PG
Respected Advisor
Posts: 3,777

Re: Proc Transpose Question

When transposing mixed var lists the numeric variables are converted to numeric using their associated formats.  Very powerful, like a VVALUE en masse.

Super Contributor
Posts: 1,636

Re: Proc Transpose Question

Hi DN,

I don't know what do you mean:smileyblush:. Would you please provide an example?  Thank you!

Respected Advisor
Posts: 3,777

Re: Proc Transpose Question

Here is a like to an application:

http://www.lexjansen.com/mwsug/2011/pharma/MWSUG-2011-PH02.pdf

This example is a bit contrived.

proc format;
  
value age
     
10-12='Pre-teen'
     
13-17='Teen'
      other=
'Older'
      ;
   run;
proc transpose data=sashelp.class out=tall;
   by name;
   var sex _numeric_;
   format age age. weight F8.3 height dollar9.2;
  
run;
proc print;
  
run;

1AlfredSexM
2AlfredAgeTeen
3AlfredHeight$69.00
4AlfredWeight112.500
5AliceSexF
6AliceAgeTeen
7AliceHeight$56.50
8AliceWeight84.000
9BarbaraSexF
10BarbaraAgeTeen
11BarbaraHeight$65.30
12BarbaraWeight98.000
13CarolSexF
Super Contributor
Posts: 1,636

Re: Proc Transpose Question

Thank you DN for the example and the link! !  I am going to read your article and ask you if I have more qurstions. 

Respected Advisor
Posts: 4,651

Re: Proc Transpose Question

I think you will have to do two transpositions. One for numeric and one for character variables. Something like this :

data have;
input a$ x b$ y c$ z;
datalines;
1 2 3 4 5 6
;

proc transpose data=have out=haven;
var _numeric_;
run;

proc transpose data=have out=havec;
var _character_;
run;

data havenc;
set haven;
length col1c $12;
col1c = strip(put(col1, best12.));
drop col1;
run;

data want;
set havenc(rename=col1c=col) havec(rename=col1=col);
run;

PG

PG
Regular Contributor
Posts: 173

Re: Proc Transpose Question

Thank you PG for your suggestion!  I really appreciate it!

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 9 replies
  • 463 views
  • 0 likes
  • 5 in conversation