data _null_;
call symput ('timenow',put (time(),time.));
if &timenow >= 17:30:00 and &timenow < 17:35:00 then
%let reportname= LSR2_Down_Report_4;else
if &timenow >= 20:30:00 and &timenow < 24:35:00 then
%let reportname= LSR2_Down_Report_6;
run;
%put &timenow &reportname;
I am attempting to assign a reportname based on the time of day.
When I run the code I get the following error
SYMBOLGEN: Macro variable TIMENOW resolves to 17:40:48
49 if &timenow >= 17:30:00 and &timenow < 17:35:00 then
SYMBOLGEN: Macro variable TIMENOW resolves to 17:40:48
NOTE: Line generated by the macro variable "TIMENOW".
49 17:40:48
_
388
76
ERROR 388-185: Expecting an arithmetic operator.
ERROR 76-322: Syntax error, statement will be ignored.
First assign timenow to a data step character var. The result of put is a char string. Then you can use call symput to assign it. . YOu also need to use call symput to assign reportname
To compare time to a literal time you need to use a value like '17:30:00't and compare the actual time value instead of a character (macro variable as created which has other issues)
data _null_; if '17:30:00't le time() < '17:35:00't then call symputx('reportname','LSR2_Down_Report_4'); else if '20:30:00't le time() < '24:35:00't then call symputx('reportname','LSR2_Down_Report_4'); else call symputx('reportname','somethingelse'); run; %put Reportname = "&reportname.";
And to add to others: The time() function starts counting seconds at the beginning of each new day. So for anything that spans over midnight you need to build logic accordingly (not done in below code).
%let timenow=;
%let reportname=;
data _null_;
timenow=time();
call symputx('timenow',put(timenow,time.));
if '17:30:00't<=timenow<='17:35:00't then
call symputx('reportname','LSR2_Down_Report_4');
else
if '20:30:00't<=timenow<='24:35:00't then
call symputx('reportname','LSR2_Down_Report_6');
stop;
run;
%put &=timenow;
%put &=reportname;
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!
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.
Ready to level-up your skills? Choose your own adventure.