BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Sorry This post is continuation of the previous post (Loop in SAS) .Thanks

NOTE: I am also not sure about this line in the code too: where myTIME lt '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.

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 lt '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;
2 REPLIES 2
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
You have a basic SAS DATA step syntax error in your DATA statement (to start). Explain what it is you want to accomplish with the {i} coding technique. Also, for incrementing/decrementing SAS DATE, TIME, and DATETIME (numeric) variables, investigate using the INTNX function in the SAS DATA step.

Scott Barry
SBBWorks, Inc.
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
If you need to execute a set of SAS code iteratively, substituting a value like {i}, you will need to investigate using the SAS MACRO language %DO / %END and substituting a macro variable used in the %DO loop processing. The macro would generate, compile and execute a series of SAS DATA/PROC steps based on your macro logic.

Scott Barry
SBBWorks, Inc.


Google advanced search argument for reference topics/DOC/papers:

macro language iterative do processing site:sas.com

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 711 views
  • 0 likes
  • 2 in conversation