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!

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!

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
  • 1586 views
  • 0 likes
  • 2 in conversation