BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
somebody
Lapis Lazuli | Level 10

I would like to calculate returns using PROC EXPAND. I could use just a simple DATA step but I would like to learn more about PROC EXPAND. 

My dataset has 3 columns containing stock, date, and price. I could use the following DATA step:

data stocks;
    set stocks;
    by stock date ;
    return=price/lag(price)-1;
    if first.stock then return=.;
run;

But How do I do  this using PROC EXPAND? in particular, what do I put in the TRANSFORMIN and TRANSFORMOUT ?

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
learsaas
Quartz | Level 8
proc sort data=stocks;
	by stock date;
run;
proc expand data=stocks out=result(drop=time);
	by stock;
	 convert price=return / transformout=( ratio 1 -1);
run;

View solution in original post

3 REPLIES 3
learsaas
Quartz | Level 8
proc sort data=stocks;
	by stock date;
run;
proc expand data=stocks out=result(drop=time);
	by stock;
	 convert price=return / transformout=( ratio 1 -1);
run;
somebody
Lapis Lazuli | Level 10

Thanks. just to confirm if I understand the code correctly, 

transformout=( ratio 1 -1)

means getting the ratio of the current value over lag 1 and then minus 1 to get the return right? So, say if I want to get returns between now and 4 periods ago, it should be:

transformout=( ratio 4 -1)

 Am I correct?

SAS INNOVATE 2024

innovate-wordmarks-white-horiz.png

SAS is headed back to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team.

Interested in speaking? Content from our attendees is one of the reasons that makes SAS Innovate such a special event!

Submit your idea!

What is Bayesian Analysis?

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 680 views
  • 2 likes
  • 2 in conversation