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 All,

My current code is like that where I create 2 macro variables (current_date , prior_business_day ) for  using %let.

Can you please help me to make SAS generate these 2 macro variable automatically?

Thank you,

HHC

 

%let current_date = 20221026_ ;


%let prior_business_day = '25OCT2022'd; data temp; infile "C:\myfolder\&current_date.sales_data.csv" ; input ... run; data temp2; set mydata; if date= &prior_business_day ; run;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

@hhchenfx wrote:

 

My current code is like that where I create 2 macro variables (current_date , prior_business_day ) for  using %let.


I didn't use %LET as I think creating these macro variables in a DATA step is easier.

 

data _null_;
    current_date=today();
    /* If today is a Sunday, then set current date back one day to Saturday */
    if weekday(current_date)=1 then current_date=current_date-1;
    prior_business_day=current_date-1;
    /* if prior_business_day is Sunday, set it back one day */
    if weekday(prior_business_day)=1 then prior_business_day=prior_business_day-1;
    call symputx('current_date',current_date);
    call symputx('prior_business_day',prior_business_day);
run;

%put %sysfunc(putn(&current_date,date9.));
%put %sysfunc(putn(&prior_business_day,date9.));  

 

--
Paige Miller

View solution in original post

6 REPLIES 6
mkeintz
PROC Star

You need to let us know what the structure of the business calendar is.  For instance, is it all Monday-Fridays, minus selected holidays?  If so, you have to confirm that rule and identify the holidays.  

 

In addition, if you run the program on a non-business day, do you assign the most recent business day as the "current business day"?  

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
hhchenfx
Barite | Level 11

Thank you for your response.

For my work, current_date is today's date and it can be any day except for Sunday.

prior_business_day is the last business day before today.

For example, if today is Sat then current_date is (always) today and prior_business_day is last Friday (if not holiday).

HHC

PaigeMiller
Diamond | Level 26

What holidays does your business observe?

--
Paige Miller
hhchenfx
Barite | Level 11
@PaigeMiller,
Business observe doesn't matter. Include or exclude is fine.
PaigeMiller
Diamond | Level 26

@hhchenfx wrote:

 

My current code is like that where I create 2 macro variables (current_date , prior_business_day ) for  using %let.


I didn't use %LET as I think creating these macro variables in a DATA step is easier.

 

data _null_;
    current_date=today();
    /* If today is a Sunday, then set current date back one day to Saturday */
    if weekday(current_date)=1 then current_date=current_date-1;
    prior_business_day=current_date-1;
    /* if prior_business_day is Sunday, set it back one day */
    if weekday(prior_business_day)=1 then prior_business_day=prior_business_day-1;
    call symputx('current_date',current_date);
    call symputx('prior_business_day',prior_business_day);
run;

%put %sysfunc(putn(&current_date,date9.));
%put %sysfunc(putn(&prior_business_day,date9.));  

 

--
Paige Miller

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 6 replies
  • 402 views
  • 0 likes
  • 3 in conversation