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

Hi all, 

I have a macro variable with the following date: "20200622" (yymmddn8. format). What I need to do is to compare it to a list of Datetime values (e.g. 01JAN2020:01:00:02) in order to exclude those that are less or equal to the date stored within the macro variable.

What am I supposed to do? I am a bit lost. Any help is appreciated. Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
salvavit
Fluorite | Level 6

Hello Kurt and thanks for the reply. 

Actually, I might have solved the issue in the meantime, although using a different solution than yours. This is what I wrote:

data table_2 (drop=day_p);
set table_1;
day_pp = datepart(input(day_p,yymmddn8.));
run;

data table_3 (rename=day_pp = day_p);
set table_2;
where put(day_pp, yymmddn8.) >= "&MACRODATE";
run;

It seems to be working.

View solution in original post

3 REPLIES 3
Kurt_Bremser
Super User

Do not format macro variables, that makes it only harder to use them.

data _null_;
call symputx("cutoff",input("20200622",yymmdd8.));
run;

Then you can compare them to the datepart of a datetime value:

data test;
input dt :datetime19.;
format dt datetime19.;
del = &cutoff. gt datepart(dt);
datalines;
01JAN2020:01:00:02
23jun2020:01:00:02
;
salvavit
Fluorite | Level 6

Hello Kurt and thanks for the reply. 

Actually, I might have solved the issue in the meantime, although using a different solution than yours. This is what I wrote:

data table_2 (drop=day_p);
set table_1;
day_pp = datepart(input(day_p,yymmddn8.));
run;

data table_3 (rename=day_pp = day_p);
set table_2;
where put(day_pp, yymmddn8.) >= "&MACRODATE";
run;

It seems to be working.

Kurt_Bremser
Super User

This is also valid, because the format in the PUT function tells everybody how the value in the macro variable should be formatted.

Personally, I prefer the "raw" method, as I can directly compare the SAS dates without using a PUT or INPUT function.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 3 replies
  • 860 views
  • 1 like
  • 2 in conversation