Hey All,
I am trying to write a code in SAS where from
Tuesday to Friday, it gets data from previous day (Trans_Date is the variable) and on Monday, I want it to get all three days data from the weekend. Appreciate all the help I get.
WEEKDAY() function tells you what day of the week it is.
First thing is to make sure that you have SAS date valued variables.
Then there are several date related functions that may help.
To get specific examples you need to provide data that you have now and what you expect.
Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the </> icon or attached as text to show exactly what you have and that we can test code against.
Another way to approach this is to maintain a dataset that has a single value...the date it last ran. You then pass that value into a start_date variable that can be used in your program. At the very end, you overwrite the dataset with today's date, that becomes the start date, the next time you run it. This way, if you happen to have a day it can't run during the week, you pick up that data the next day it does run.
libname mydata "directory_path";
data _null_;
set mydata.last_run_date;
call symputx('start_date',"'"||put(date_last_run,date9.)||"'d");
run;
data want;
set have;
where date_var >= &start_date. and date_var < date();
run;
data mydata.last_run_date;
date_last_run=date();
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.