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\¤t_date.sales_data.csv" ;
input ...
run;
data temp2; set mydata;
if date= &prior_business_day ;
run;
@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(¤t_date,date9.));
%put %sysfunc(putn(&prior_business_day,date9.));
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"?
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
What holidays does your business observe?
@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(¤t_date,date9.));
%put %sysfunc(putn(&prior_business_day,date9.));
Thank you so much!
HHC
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!
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.