%macro testmacro;
%let run_time=%sysfunc(time(),time16.);
%let start_time=%sysfunc(putc(19:30:00,time16.)); /*from today 19:00 to tommarow 07:00 AM */
%let end_time=%sysfunc(putc(07:00:00,time16.));
%let test_value =((&start_time. > &run_time.) or (&run_time. < &end_time.));
%put this is to test test_value :::&test_value.;
%if ((&start_time. > &run_time.) or (&run_time. < &end_time.)) %then %do;
%put execute the code;
%end;
%else %do;
%put dont execute the code;
%end;
%mend;
%testmacro;
Hello Team ,
am trying to execute above code , it works perfectly when i execute from sas EG
But when i am trying to execute with sas BI webservices (which uses sassrv account (stored process server)
to execute this code am getting below error message
WARNING: Argument 2 to function PUTC referenced by the %SYSFUNC or %QSYSFUNC macro function is out of range.
The SAS System
WARNING: Argument 2 to function PUTC referenced by the %SYSFUNC or %QSYSFUNC macro function is out of range.
this is to test test_value :::(( > 18:38:33) or (18:38:33 < ))
Means the start_time and end_time are not resolved because of above warning message and always
entered in to else statement
can you post your suggestions on this
I am surprised that your PUTC works at all, as TIME is not a character format.
Use SAS time values (count of seconds) throughout your code, and you can use macro variables containing the raw values without hassle:
%let start_time=%sysevalf('19:30:00't);
%put &=start_time.;
%let start_time=%sysfunc(inputn(19:30:00,time8.));
%put &=start_time;
Two simple methods of converting human-readable strings into time values that can be used anywhere where comparisons with SAS time values are needed.
I am surprised that your PUTC works at all, as TIME is not a character format.
Use SAS time values (count of seconds) throughout your code, and you can use macro variables containing the raw values without hassle:
%let start_time=%sysevalf('19:30:00't);
%put &=start_time.;
%let start_time=%sysfunc(inputn(19:30:00,time8.));
%put &=start_time;
Two simple methods of converting human-readable strings into time values that can be used anywhere where comparisons with SAS time values are needed.
..for completeness..
**TIME;
%let start_time=%sysevalf('19:30:00't);
%put &=start_time.;
%let start_time=%sysfunc(inputn(19:30:00,time8.));
%put &=start_time;
**DATE;
%let start_date=%sysevalf('19mar2021'd);
%put &=start_date.;
%let start_date=%sysfunc(inputn(19mar2021,date9.));
%put &=start_date;
** DATETIME;
%let start_datetime=%sysevalf('19mar2021 15:12:22'dt);
%put &=start_datetime.;
%let start_datetime=%sysfunc(inputn(19mar2021:15:12:22,anydtdtm23.));
%put &=start_datetime;
What are you trying to do?
You are currently taking a circular route to setting macro variables to strings (complete with colons in them) that will look to humans a lot like time of day values. You could do that much easier.
%let run_time=%sysfunc(time(),time8.);
%let start_time=19:30:00;
%let end_time=07:00:00;
But using the TIME format instead of the TOD format will cause trouble when run before 10 AM since it will not include the leading zero. So 8AM will come out as "8:00:00" instead of "08:00;00" and so it will be larger than both your other strings instead of being between them.
%let run_time=%sysfunc(time(),tod8.);
If you want to compare times across days you probably want to use DATETIME values.
For example if you want to calculate execution duration you should use DATETIME values just in case you start on one date and end on another.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.