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: 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
  • 4 replies
  • 943 views
  • 4 likes
  • 4 in conversation