BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SASuser403
Calcite | Level 5

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
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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

2 REPLIES 2
Reeza
Super User

PROC TRANSPOSE - as you've indicated 🙂

 

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;
Tom
Super User Tom
Super User

Just use PROC TRANSPOSE.

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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 2 replies
  • 6431 views
  • 2 likes
  • 3 in conversation