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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 922 views
  • 0 likes
  • 2 in conversation