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
Just use PROC TRANSPOSE.
proc transpose data=have out=want(drop=_: )
prefix=Bucket_
;
by symbol date ;
id bucketno ;
var turnover;
run;
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;
Just use PROC TRANSPOSE.
proc transpose data=have out=want(drop=_: )
prefix=Bucket_
;
by symbol date ;
id bucketno ;
var turnover;
run;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.