Help using Base SAS procedures

Help with Transpose

Reply
Frequent Contributor
Posts: 124

Help with Transpose

data have;

input start_dt mmddyy10. calls 3.;

datalines;

10/26/2015 10

11/02/2015 12

11/09/2015 10

11/16/2015 8

;

proc sort data=have;

by start_dt;

run;

 

proc transpose data =have out=want (drop=_name_);

id start_dt;

var Calls;

run;

 

It gives me output as below:

 

_10_26_2015 _11_02_2015    _11_09_2015    _11_16_2015

      10                        12                  10                    8

 

But I want the Output as follows:

 

10/26/2015     11/02/2015         11/09/2015          11/16/2015

     10                       12                   10                     8

Super Contributor
Posts: 275

Re: Help with Transpose

[ Edited ]

After transposed, date became variable name, in SAS, variable name is not allowed with digit at the first letter, and '/' is not allowed, but '_ ' is Ok. You could use label in transpose, such as:


proc transpose data =have out=want (drop=_name_);
id start_dt;
var Calls;
label _10_26_2015='10/26/2015';
run;

Super User
Posts: 17,785

Re: Help with Transpose

 Those wouldn't be valid SAS variable names.

 

You can apply them as labels though by adding the IDLABEL line to your proc transpose code.

 

idlabel start_dt;
Super User
Posts: 10,487

Re: Help with Transpose

That approach generates a real ugly dataset for much use. What will you do with the transposed data?

 

You you are looking for a pretty table appearance then use a report procedure such as Proc Report or tabulate.

Respected Advisor
Posts: 4,644

Re: Help with Transpose

"10/26/2015" is not a valid SAS variable name. Anyway, that's not what you get with the code you posted. You can use IDLABEL=

 

data have;
input start_dt mmddyy10. calls 3.;
format start_dt mmddyy10.;
datalines;
10/26/2015 10
11/02/2015 12
11/09/2015 10
11/16/2015 8
;
proc sort data=have;
by start_dt;
run;
 
proc transpose data =have out=want (drop=_name_);
id start_dt;
idlabel start_dt;
var Calls;
run;
PG
Ask a Question
Discussion stats
  • 4 replies
  • 331 views
  • 0 likes
  • 5 in conversation