BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
learn_SAS_23
Quartz | Level 8
%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

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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.

View solution in original post

5 REPLIES 5
Kurt_Bremser
Super User

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.

learn_SAS_23
Quartz | Level 8
Thanks for quick help ,it works with count of seconds
AndreaVianello
Obsidian | Level 7

..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;

Tom
Super User Tom
Super User

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.

learn_SAS_23
Quartz | Level 8
Thanks for finding it out and tips , as i am a learner to the macro language trying different ways to define time constant to a variable.
thanks so much for tips .

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