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

Hi,

 

I have defined an macro prev_day

 

%let prev_day = sysfunc(intnx(day, %sysfunc(today(),-1), date9.)

I have a column name data_loade_dt, which is datetime 

I wish to select the data loaded before previous date,

so in my where condition I write:

 

where datepart(date_load_dt) < '& prev_day'd

Which result a wrong format SAS cannot compare the pre_day in my selection.

 

Please advise.

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

Assuming your real code was already of better quality than what you've posted the reason is likely that you've enclosed the macro variable in single quotes. You need double quotes for the macro variable to resolve.

 

Below working sample code with all the syntax you've posted fixed.

%let prev_day = %sysfunc(intnx(day, %sysfunc(today()),-1), date9.);
%put &=prev_day;

data have;
  format date_load_dttm datetime21.;
  do i=-3 to 3;
    date_load_dttm=intnx('dtday',datetime(),i); 
    output;
  end;
run;

data want;
  set have;
  if datepart(date_load_dttm) < "&prev_day"d;
run;

View solution in original post

2 REPLIES 2
Patrick
Opal | Level 21

Assuming your real code was already of better quality than what you've posted the reason is likely that you've enclosed the macro variable in single quotes. You need double quotes for the macro variable to resolve.

 

Below working sample code with all the syntax you've posted fixed.

%let prev_day = %sysfunc(intnx(day, %sysfunc(today()),-1), date9.);
%put &=prev_day;

data have;
  format date_load_dttm datetime21.;
  do i=-3 to 3;
    date_load_dttm=intnx('dtday',datetime(),i); 
    output;
  end;
run;

data want;
  set have;
  if datepart(date_load_dttm) < "&prev_day"d;
run;
sarahzhou
Quartz | Level 8

@Patrick , thank you! It worked!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Autotuning Deep Learning Models Using SAS

Follow along as SAS’ Robert Blanchard explains three aspects of autotuning in a deep learning context: globalized search, localized search and an in parallel method using SAS.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 2456 views
  • 0 likes
  • 2 in conversation