BookmarkSubscribeRSS Feed
cjohnson
Obsidian | Level 7
I am trying to write a macro that checks a table every 60 seconds to see if there is an entry for today's date. If not, it sleeps 60 seconds, if found, it starts a process. I think I have two problems: not sure if I am using Call Symput correctly, and the &sysdate is character, and I am trying to compare to a date (numberic) value. Any help would be greatly appreciated!

%MACRO AUTO();
%LET WAIT = 'TRUE';
%DO %WHILE (&WAIT = 'TRUE');
%SLEEP(60);
DATA _NULL_;
SET FILES.CHECK;
IF DATE = "&SYSDATE" THEN CALL SYMPUT('WAIT', 'FALSE');
RUN;
%END;
/*PROCESS*/
%MEND AUTO;
Christopher Johnson
www.codeitmagazine.com
10 REPLIES 10
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
There is no %SLEEP macro, unless you have defined it, possibly to use a DATA step with SLEEP function? You may want to explore the use of %SYSFUNC and invoking a CALL function in that manner without a DATA step.

Also the &SYSDATE value (in double-quotes) must be identified as a SAS DATE constant by adding the "D" suffix to the quoted string.


Scott Barry
SBBWorks, Inc.
cjohnson
Obsidian | Level 7
Thank you so much! I have a sleep macro, but I had completely forgotten to use the d to make sysdate a data constant. Works great now. I included the working code below in case it helps anyone else.

%MACRO AUTO();
%LET WAIT = 'TRUE';
%DO %WHILE (&WAIT = 'TRUE');
%SLEEP(2);
DATA _NULL_;
SET FILES.CHECK;
IF DATE = "&SYSDATE"D THEN CALL SYMPUT('WAIT', 'FALSE');
RUN;
%END;
/*PROCESS*/
%PUT "IT WORKED!";
%MEND AUTO;

%MACRO SLEEP(SECONDS);
DATA _NULL_;
Var1 = SLEEP(&SECONDS);
RUN;
%MEND SLEEP;
Christopher Johnson
www.codeitmagazine.com
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
If appropriate, the %SLEEP macro can be eliminated by using:

%LET X = %SYSFUNC(SLEEP(60));

Also, if you only need to detect the presence of at least one obs for the current date, consider using a WHERE and also have a DO/END loop to invoke the SYMPUT, along with a STOP; statement -- given what you have shown for a DATA step invocation, there is really no need to pass the entire file, right? Just a thought for SAS programming optimization.

Scott Barry
SBBWorks, Inc.
cjohnson
Obsidian | Level 7
Great tips. I replaced the sleep function, and the where statement really helped.

Thanks.
Christopher Johnson
www.codeitmagazine.com
cjohnson
Obsidian | Level 7
I have one more question if you don't mind. I am calling the macro with the following parameters, and it works great:

%LET CURR = "&SYSDATE"D - 1;
%LET PREV = "&SYSDATE"D - 2;

How do I get the date one month prior (i.e. 6/19/09 and 5/19/09), since the number of days to subtract will vary?
Christopher Johnson
www.codeitmagazine.com
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
If you intend to do it macro-based, you will need to work with %SYSFUNC and look at the DATE-related functions (normally used in a DATA step but accessible in macro language when using SYSFUNC. Then construct a new macro variable, again using SYSFUNC, and the MDY function.

Suggest in the future you consider creating a new post for a new question or discussion topic.

Scott Barry
SBBWorks, Inc.
Peter_C
Rhodochrosite | Level 12
the INTNX() function has a SAMEDAY parameter (in place of begin/end/middle)

%put %sysfunc( intnx( month, "21Jun2009"d, -1, sameday ),date9 ) ;
should report 21May2009 in the log
(works for me)
PeterC
Augusto
Obsidian | Level 7

Peter

Very nice to know about SAMEDAY parameter in intnx function.

Thanks.

DanielSantos
Barite | Level 11
Also, you should consider working with the lock table features.

If any process tries to write something, while you checking (reading) the table, or you try to check the table while its being written to, you'll get an error (unless it's a SAS/SHARE library or, your SO is able to do the lock handling, like z/OS).

See the online documentation:
http://support.sas.com/documentation/cdl/en/shrref/59595/HTML/default/a000203947.htm

Cheers from Portugal.

Daniel Santos @ www.cgd.pt
cjohnson
Obsidian | Level 7
Thanks. I had just run into that problem!
Christopher Johnson
www.codeitmagazine.com

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