BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi I am trying to replicate a loop in Excel VBA using SAS but being quite a new user, am not quite sure how to proceed.

I have prices recorded over time from 8.30am to 3.05pm on a daily basis for five years and want to estimate a rolling window with a one-minute interval. For example, I want to estimate average of prices each day from 8.31am to 2.06pm. The next window is going to be from 8.32am to 2.07pm and so on until the last window which is from 9.30am to 3.05pm.

The {i} refers to increments of 1minute. I want to rename the dataset with the {i} number as well.

The loop starts from {i} = 1 to 60.

I have written this code below and have been trying to trying to replace {i} with the numbers in the loop.

NOTE: I am also not sure about this line in the code too: "where myTIME <= '14:05:00't + minute{i};" . I am trying to put a limit to tell SAS where I want it to end each day and to increment that ending time by 1 minute each time.


thanks
c+

****************************************
data work.{i}test;
set work.source;
by myDay;
retain ORIGINDatetime;
FIRSTOBS = first.myDay;
if FIRSTOBS then do;
ORIGINDatetime = myDateTime + (60 * {i});
end;
format ORIGINDatetime datetime.;
run;

data work.{i}test01;
set work.{i}test;
where myTIME <= '14:05:00't + minute{i};
run;

proc sql;
create table work.{i}test02 as
select myDay,mean(price) as avg_price
from work.{i}test01
group by myDay;
quit;
1 REPLY 1
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Closing the loop....see reply here:

http://support.sas.com/forums/thread.jspa?threadID=6023

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 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
  • 1 reply
  • 608 views
  • 0 likes
  • 2 in conversation