BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
hhchenfx
Rhodochrosite | Level 12

Hi,

I want to compare current time with '4:55't as below but my code is not working.

Can you please help to fix?

Thanks,

HHC

%MACRO _BREAK() ;
%let current_time = time(); /* Get the current time */

%IF &current_time < '4:55't %then %do;
	%put "print before ";
	%END;
%ELSE %do;
	%put "print after";
	%END;

%Mend;

%_BREAK();

 

1 ACCEPTED SOLUTION

Accepted Solutions
LynnP_sas
SAS Employee

Greetings,

I made the following modifications to your code:

 

%MACRO _BREAK() ;
%let current_time = %sysfunc(time()); /* Get the current time */
%put curr is &current_time;
%IF %sysevalf(&current_time < '20:55't) %then %do;
%put "print before ";
%END;
%ELSE %do;
%put "print after";
%END;
 
%Mend;
%_BREAK();
 
The problems you were having are due to the macro facility only understanding text.

View solution in original post

4 REPLIES 4
Kurt_Bremser
Super User
%let current_time = time(); /* Get the current time */

Here, you assign the text time() to the macro variable (not the result of the function!). If you want to execute a data step function in macro code, you need to use %SYSFUNC:

%let current_time = %sysfunc(time());
SASKiwi
PROC Star

It's a lot easier not using macro logic - not sure why you need a macro at all:

%MACRO _BREAK() ;

data _null_;
  if time() < '4:55't then putlog "print before ";
  else putlog "print after";
run;

%Mend;

%_BREAK();
LynnP_sas
SAS Employee

Greetings,

I made the following modifications to your code:

 

%MACRO _BREAK() ;
%let current_time = %sysfunc(time()); /* Get the current time */
%put curr is &current_time;
%IF %sysevalf(&current_time < '20:55't) %then %do;
%put "print before ";
%END;
%ELSE %do;
%put "print after";
%END;
 
%Mend;
%_BREAK();
 
The problems you were having are due to the macro facility only understanding text.
hhchenfx
Rhodochrosite | Level 12

Thank you so much for helping!

HHC

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1497 views
  • 4 likes
  • 4 in conversation