BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Eliot1
Fluorite | Level 6

Hello All,

 

I would like to know if my traitement finish before 09:15 AM :

%let statut = OK;

data _null_;
call symput ('timenow',put (time(),hhmm.));
run;
%put &timenow;
--09:08

%macro tempsko;
%if '09:15't <= &timenow %then %do;
%let statut=KO;
%end;
%mend;
%tempsko;
%put &statut;

-- KO ???

Thx for your help 

1 ACCEPTED SOLUTION

Accepted Solutions
Eliot1
Fluorite | Level 6

This code work :

 

 

%let statut = OK;
%put &statut;

data _null_;
call symput ('timenow', time());
run;
%macro tempsko; %if %sysevalf('09:15't <= &timenow) %then %do; %let statut=KO; %end; %mend; %tempsko; %put &statut;

Thx all for your help

 

View solution in original post

12 REPLIES 12
Kurt_Bremser
Super User

Since timenow contains a string and not a number, a character comparison is used, and the single quote comes before any digit in the ASCII table. Make a time literal out of your timenow reference:

%let statut = OK;

data _null_;
call symput ('timenow',put (5000,hhmm.));
run;
%put &timenow;

options mprint mlogic symbolgen;

%macro tempsko;
%if '09:15't <= "&timenow"t %then %do;
%let statut=KO;
%end;
%mend;
%tempsko;
%put &statut;
Eliot1
Fluorite | Level 6

Sorry, it does not work.

Une nouvelle formulation serait : Comment puis-je tester si mon traitement est passé avant 09:15 AM

Thx for tour time

Satish_Parida
Lapis Lazuli | Level 10
%let statut = OK;

data _null_;
call symput ('timenow',put (time(),hhmm.));
run;
%put &timenow;


%macro tempsko;
	data _null_;
	if '09:15't le "&timenow"t then call symput('statut','KO');
	run;
%mend;
%tempsko;

%put &statut;

Please let us know if this worked for you.

Tom
Super User Tom
Super User

The implied %EVAL() function call of the %IF statement does not recognize date/time/datetime literals.  Make an explicit call to %SYSEVALF()  instead.  Also you are comparing the string 09:80 to the time value '09:15't.  

%if %sysevalf('09:15't <= "&timenow"t) %then %do;
Eliot1
Fluorite | Level 6

Sorry, it does not work.

A new formulation would be:

How can I test if my treatment is passed before 09:15 AM

Thx for tour time

Tom
Super User Tom
Super User

Show more details of what code you are using.

Eliot1
Fluorite | Level 6

%let statut=OK;
%put &statut;


data _null_;
call symput ('timenow', time());
run;
%put &timenow;

%macro tempsko;
%if '14:40't <= &timenow %then %do;
%let statut=KO;
%end;
%mend;


%tempsko;


%put &statut;

PaigeMiller
Diamond | Level 26

DO NOT format macro variables.

%let statut = OK;

data _null_;
call symput ('timenow',time()); /* NOTE: unformatted */
run;

%macro tempsko;
%if '09:15't <= &timenow %then %do;
%let statut=KO;
%end;
%mend;
%tempsko
%put &=statut;
--
Paige Miller
Eliot1
Fluorite | Level 6

It does not work 😞 

PaigeMiller
Diamond | Level 26

@Eliot1 wrote:

It does not work 😞 


Explain, please.

--
Paige Miller
Eliot1
Fluorite | Level 6

This code work :

 

 

%let statut = OK;
%put &statut;

data _null_;
call symput ('timenow', time());
run;
%macro tempsko; %if %sysevalf('09:15't <= &timenow) %then %do; %let statut=KO; %end; %mend; %tempsko; %put &statut;

Thx all for your help

 

Tom
Super User Tom
Super User

@PaigeMiller %EVAL() does not treat time (or other) literals as special cases, it just treats them as text strings. You need to explicitly call %SYSEVALF() instead of letting SAS do an implicit call to %EVAL().

sas-innovate-white.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Early bird rate extended! Save $200 when you sign up by March 31.

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 12 replies
  • 1781 views
  • 3 likes
  • 5 in conversation