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

Hi,

suppose I have the following data of stocks and their prices for different dates:

stockdateprice
A1/1/20102
A2/2/20106
A3/3/20111
B4/4/20098
B5/5/20134
B6/6/20143

What I would like to have is the for each stock its highest price and the date date when it happened (more precisely, the entire corresponding row):

stockdatehighest price
A2/2/20106
B4/4/20098

thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
naveen_srini
Quartz | Level 8

proc sort data=have out=have1;

by stock descending price;

run;

data have1;

set have1;

by stock;

if first.stock;

run;

View solution in original post

3 REPLIES 3
naveen_srini
Quartz | Level 8

proc sort data=have out=have1;

by stock descending price;

run;

data have1;

set have1;

by stock;

if first.stock;

run;

ilikesas
Barite | Level 11

Hi naveen,

thanks for the code, its actually quite simple and I probably should have been able to figure it out, but when posing the question I had in mind calculating the max as part of a bigger code.

And what a lucky coincidence!!!

Yesterday you answered my question about lagged returns with the following code: 

data ind_lag;

set ind_sect;

by sector;

k=lag(price);

if not first.sector then return = (price - k) / k;

drop k;

run;

On the same discussion, I was already given an answer for calculating the return between any 2 periods, and wanted to add to it the max price (and its date) between these 2 periods, and that's why I asked the present question.

I guess that now I can just merge max price and date table of your code with the return for each stock bw 2 periods.

Thanks again!!

naveen_srini
Quartz | Level 8

Anytime, you are most welcome!. Have a nice day

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 1627 views
  • 0 likes
  • 2 in conversation