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

Hello All

I'm trying to calculate rolling RSI (which is a financial indicate), I found this code, it should help me do the calculation. However, I'm very understand what is this piece of code doing. Would you please explain the code line by line, so that I can do the necessary changes to solve my case.  

 

%macro calRSI();

%do i=16 %to 7570;

data RSI;

set RSI;

lAveGain = lag1(AveGain);

lAveLoss = lag1(AveLoss);

if days = &i then do;

AveGain = (lAveGain*13+gain)/14;

AveLoss = (lAveLoss*13+loss)/14;

RS = AveGain / AveLoss;

RSI = 100-100/(1+RS); end;

%end; %mend;

%calRSI;

data summer.RSIresult;

set RSI;

run;

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

This code is overwriting the same dataset 7555 times, each time calculating the RSI for only one value of days. It looks like a very very inefficient way to do this type of calculation. I would advise you NOT to do this.

 

Tell us instead about your available data and the calculation you want to perform, especially the details of the smoothed moving averages.

PG

View solution in original post

3 REPLIES 3
PGStats
Opal | Level 21

This code is overwriting the same dataset 7555 times, each time calculating the RSI for only one value of days. It looks like a very very inefficient way to do this type of calculation. I would advise you NOT to do this.

 

Tell us instead about your available data and the calculation you want to perform, especially the details of the smoothed moving averages.

PG
Xinhui
Obsidian | Level 7

Thank you for helping, I have used "proc expand" code solved the problem. Still thank you. 

PGStats
Opal | Level 21

Very wise choice. Congratulations!

PG

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!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

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