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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 5 replies
  • 593 views
  • 0 likes
  • 2 in conversation