BookmarkSubscribeRSS Feed
samira
Obsidian | Level 7

Hello;

 

Since I do not have ETS package licensed, I am trying to use data step in sas to calculate EWMA (Exponential Weighted Moving Average). 

 

Let me give you an example of what I need to calculate EWMA. Assume I have the following dataset: 

 

Capture.PNG

 

I want to add two columns named "smoothed" and "forecasted". the first element of the forcasted column is average of the "ILI_Percent", so we have: 

Capture.PNG

 

the smoothed value of each row is going to be :  0.5 * ILI_Percent [i] + 0.5 * forecasted[i] 

 

and the next value of the forecasted column is equal to the prevouis value of smoothed column: smoothed[i]=forecasted[i+1]

so we are going to have: 

Capture.PNG

 

I am trying to do the same thing in data step, but I am not sure how can I reach to previous element of a column in data step. I would be appriciate if someone help me with this. 

 

2 REPLIES 2
art297
Opal | Level 21

If it's something you calculate, use a retain statement to hold the value in a variable. If it is a value that is already in the dataset, use the lag function.

 

Art, CEO, AnalystFinder.com

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

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