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

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
Barite | Level 11

Thank you so much for helping!

HHC

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 980 views
  • 4 likes
  • 4 in conversation