Hi i need help in extracting data using below set of rules/instructions.
Kindly note that the reason for all of above is because I need to schedule the code to run automatically during weekdays(monday to friday), your help will be highly appreciated!
Data HAVE
data leave; input process_date :yymmdd10. amount reference &:$50.; format process_date yymmdd10.; datalines; 2022-01-08 100 trn01 2022-01-09 200 trn02 2022-01-10 300 trn03 2022-01-11 400 trn04 2021-01-12 500 trn05 2022-01-13 600 trn06 2022-01-14 700 trn07 2022-01-15 800 trn08 2022-01-16 900 trn09 2022-01-17 1000 trn10 ;
Data Want - for process date "2022-01-13" which is thursday (First bullet point on the rules/instructions)
process_date amount reference
2022-01-13 600 trn06
Data Want - for process date "2022-01-12" which is wednesday (Second bullet point on the rules/instructions)
process_date amount reference
2022-01-12 500 trn05
Data Want - for process date "2022-01-10" which is Monday (3rd bullet point on the rules/instructions)
process_date amount reference
2022-01-08 100 trn01
2022-01-09 200 trn02
2022-01-10 300 trn03
I would do this:
data _null_;
rundate = ifn(weekday(today()) in (5,6),today() + 4,today() + 2);
call symputx('rundate',rundate);
run;
On Thursday and Friday, it jumps to Monday and Tuesday respectively, on Monday, Tuesday and Wednesday just two days ahead.
Extract the data from where?
Your description of "skip" does not quite align with what I think you are showing for describing for dates used. You appear to actually be using 3 dates on Mondays, not skipping anything. Please clarify the description.
Note that the WEEKDAY function returns the day of the week, 1 for Sunday to 7 for Saturday, for a valid date value. So you can test the TODAY() function to see what day code is running. So given those two functions you should be able to create "process date" values.
So you want to go two workdays into the future? What about holidays that fall on a Monday-Friday?
I would do this:
data _null_;
rundate = ifn(weekday(today()) in (5,6),today() + 4,today() + 2);
call symputx('rundate',rundate);
run;
On Thursday and Friday, it jumps to Monday and Tuesday respectively, on Monday, Tuesday and Wednesday just two days ahead.
You run my code before your analysis, and then use
where process_date = &rundate.
to select the observations.
I used a DATA _NULL_ step to keep the code more readable; basically, you can calculate the rundate in a single %LET with a lot of %SYSFUNCs in between.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.