BookmarkSubscribeRSS Feed
Q1983
Lapis Lazuli | Level 10

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.

 

3 REPLIES 3
DavePrinsloo
Pyrite | Level 9

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

ballardw
Super User

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.";
Patrick
Opal | Level 21

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;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 3 replies
  • 542 views
  • 2 likes
  • 4 in conversation