BookmarkSubscribeRSS Feed
Takdir
Obsidian | Level 7

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
2 REPLIES 2
andreas_lds
Jade | Level 19

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.

Kurt_Bremser
Super User

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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 723 views
  • 1 like
  • 3 in conversation