BookmarkSubscribeRSS Feed
ssomak
Fluorite | Level 6
Dear all, I would like to write a macro program, that will work until a given datetime (passed as a parameter). I wrote something like this: %global current; %macro test_loop(dt); data _null_; call symput('current', put(datetime(), best12.)); %let end_dt=%sysfunc(inputn(&dt., datetime.)); run; %do %until (&current.>&end_dt.); /* %include 'some_program.sas';*/ data _null_; call symput('current', put(datetime(), best10.0)); %put &current.; run; %end; %mend test_loop; %test_loop('27FEB2018:15:00:00'); But unfortunatelly it doesn't work. Can anyone help me please 🙂 ? Thanks in advance!
5 REPLIES 5
ssomak
Fluorite | Level 6

 Hi again,

 

Something wrong went with formatting, so I paste my post again:

 

 Dear all,

 

I would like to write a macro program, that will work until a given datetime. I wrote something like this:

%global current;

%macro test_loop(dt);
data _null_;
call symput('current', put(datetime(), best12.));
%let end_dt=%sysfunc(inputn(&dt., datetime.));
run;

%do %until (&current.>&end_dt.);

/* %include 'some_program.sas';*/

data _null_;
call symput('current', put(datetime(), best10.0));
%put &current.;
run;
%end;
%mend test_loop;

%test_loop('27FEB2018:15:00:00');

 

But unfortunatelly it doesn't work. Can anyone help me please Smiley Happy ?

 

 Thanks in advance!

Kurt_Bremser
Super User

Please use the proper subwindow for posting code, and use visual formatting to make your code readable, like this:

%global current;

%macro test_loop(dt);

data _null_;
call symput('current', put(datetime(), best12.));
%let end_dt=%sysfunc(inputn(&dt., datetime.));
run;

%do %until (&current.>&end_dt.);

  /* %include 'some_program.sas';*/

  data _null_;
  call symput('current', put(datetime(), best10.0));
  %put &current.;
  run;

%end;

%mend test_loop;

%test_loop('27FEB2018:15:00:00');

And please define "doesn't work".

ssomak
Fluorite | Level 6

 Hi!

 

Sure, I will use the proper subwindow (sorry, I didn't notice it before).

 

And about the definition of "doesn't work". I thought that when I run this code, in every second there will be current datetime in the log:

call symput('current', put(datetime(), best10.0));
%put &current.;

But unfortunately there is the same value for first, let's say, 5 second, another value of next 5 second and so on.

 

In general, I would like to achieve the following goal:

at 2PM I call this macro in this way:

%test_loop('27FEB2018:16:00:00');

and at 4PM it will stop work (because value of current variable will be grater that value of end_dt variable).

 

 Best,

 F.

Kurt_Bremser
Super User

Try this:

%global current;

%macro test_loop(dt);

%let end_dt=%sysfunc(inputn(&dt., datetime.));
%put end_dt=&end_dt.;

data _null_;
call symput('current', put(datetime(), best12.));
run;

%do %until (&current.>&end_dt.);

  /* %include 'some_program.sas';*/

  data _null_;
  x =sleep(5,1);
  run;

  data _null_;
  call symput('current', put(datetime(), best10.0));
  run;
  
  %put &current.;
%end;

%mend test_loop;

%test_loop(%sysfunc(intnx(minute,%sysfunc(datetime()),1),datetime19.));

it works for me.

The data _null_ with the sleep() is in there to prevent the creation of an oversized log (too many quick iterations).

ssomak
Fluorite | Level 6

 Hi again,

 

It works for me as well. So thank you very much for your help, really appreciate it !!! 🙂

 

 Best,

 F.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 5 replies
  • 1470 views
  • 0 likes
  • 2 in conversation