HI,
I am a bit stick with transposing data. would really appreciate your help with codes
this is what I have:
TICKER | DATE | PRC |
A | 2021-05-18 | 128.75 |
A | 2021-05-19 | 130.21 |
A | 2021-05-20 | 132.15 |
AAPL | 2021-05-18 | 124.85 |
AAPL | 2021-05-19 | 124.69 |
AAPL | 2021-05-20 | 127.31 |
this is what I want:
TICKER | 2021-05-18 | 2021-05-19 | 2021-05-20 |
A | 128.75 | 130.21001 | 132.14999 |
AAPL | 124.85 | 124.69 | 127.31 |
Having data in variable names is almost always a bad idea and leads to unnecessary complex code in further steps. "2021-05-18" is not a valid variable name. If you want a report as result using proc report with across-option for date you should get the layout.
For reporting purposes, use PROC REPORT:
data have;
input ticker $ date :yymmdd10. prc;
format date yymmdd10.;
datalines;
A 2021-05-18 128.75
A 2021-05-19 130.21
A 2021-05-20 132.15
AAPL 2021-05-18 124.85
AAPL 2021-05-19 124.69
AAPL 2021-05-20 127.31
;
proc report data=have;
column ticker prc,date;
define ticker / group;
define prc / "" analysis;
define date / "" across;
run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.