Hi, i need help in extracting data as per below code..as an example,if weekday(today())= 3 then i need the code to return the process_date = today()-4 meaning i need transactions with only process_date=04FEB2022
Once again if weekday(today()) = 2 then i need the code to return process_date=today()-3 meaning i will need only transactions with process_date=03FEB2022
See below data have , as well as my code attempt but i do not get desired results
data transactions; input process_date :yymmdd10. amount reference &:$50.; format process_date date9.; datalines; 2022-02-04 100 trn01 2022-02-04 200 trn02 2022-02-03 300 trn03 2022-02-02 400 trn04 2021-02-01 500 trn05 ; DATA final_data; SET transactions; if weekday(today())= 2 then process_date=today()-3; else if weekday(today())= 3 then process_date=today()-4; else if weekday(today()) in (4,5,6) then process_date=today()-2; RUN;
Sounds like you want to extract some specific process dates, rather than set the process date (which is what your code does). Try this:
DATA final_data;
SET transactions;
if weekday(today())= 2 then if process_date=today()-3;
else if weekday(today())= 3 then if process_date=today()-4;
else if weekday(today()) in (4,5,6) then if process_date=today()-2;
RUN;
Looks almost the same, but I changed the assignments to subsetting IFs.
What is incorrect about the output? If you run it today (Tuesday, February 8, 2022) then weekday(today()) gives a value of 3 and so all of your output should have process_date as today()-4, and that's exactly what happens, the resulting process_date is February 4, 2022.
Sounds like you want to extract some specific process dates, rather than set the process date (which is what your code does). Try this:
DATA final_data;
SET transactions;
if weekday(today())= 2 then if process_date=today()-3;
else if weekday(today())= 3 then if process_date=today()-4;
else if weekday(today()) in (4,5,6) then if process_date=today()-2;
RUN;
Looks almost the same, but I changed the assignments to subsetting IFs.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.