Help using Base SAS procedures

Proc Transpose Data Set Question PivotTable

Accepted Solution Solved
Reply
Occasional Learner
Posts: 1
Accepted Solution

Proc Transpose Data Set Question PivotTable

[ Edited ]

Need help using SAS procedures to change the data

Here is what my old data looks like

Symbol     Date               Bucketno Turnover

APX       20140503             22             .005

APX       20140503             23             .023

APX       20140504             17             .021

APX       20140504             21             .025

APX       20140504             24             .38

MMM     20140501             22              .06

MMM     20140501             23             .09

It has buckets variable called “bucketno” that goes from 1-24.

I would like this to be converted into a variable bucket_1 Bucket_2 Etc to Bucket_24. No Bucketno variable in final

There should be one day per row.

The values in the dataset should be Turnover, so there will be no Turnover variable in the final.

This is sorted by Symbol and Date.

I am able to do this using PivotTables in Excel. I have attacked a picture of the final result that I am trying to replicate.

How can i do this using SAS code?

Thank you


SASFinal.PNG

Accepted Solutions
Solution
‎05-06-2017 03:31 PM
Super User
Super User
Posts: 7,039

Re: Proc Transpose Data Set Question PivotTabel

[ Edited ]
Posted in reply to SASuser403

Just use PROC TRANSPOSE.

proc transpose data=have out=want(drop=_: )
  prefix=Bucket_
;
 by symbol date ;
 id bucketno ;
 var turnover;
run;

View solution in original post


All Replies
Super User
Posts: 19,772

Re: Proc Transpose Data Set Question PivotTabel

Posted in reply to SASuser403

PROC TRANSPOSE - as you've indicated Smiley Happy

 

Have you tried this already and not been able to get it to work? Is your data already in SAS?
Which part do you need help with?  

 

When using PROC TRANSPOSE the ID variable can be used to identify the record and PREFIX can be used to create the name.

The idea is below - you need to fill in the <> with your variable names.

 

proc sort data=have;
by <group vars>; *identify each line in your new dataset;
run;


proc transpose data=have out=want prefix=bucket_;
by <group vars>;
var <variable in middle area>;
id bucketno;
run;
Solution
‎05-06-2017 03:31 PM
Super User
Super User
Posts: 7,039

Re: Proc Transpose Data Set Question PivotTabel

[ Edited ]
Posted in reply to SASuser403

Just use PROC TRANSPOSE.

proc transpose data=have out=want(drop=_: )
  prefix=Bucket_
;
 by symbol date ;
 id bucketno ;
 var turnover;
run;
☑ This topic is solved.

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

Discussion stats
  • 2 replies
  • 319 views
  • 2 likes
  • 3 in conversation