BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Solly7
Pyrite | Level 9

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;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
s_lassen
Meteorite | Level 14

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.

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
Solly7
Pyrite | Level 9
Hi I get the below results after running my code,which is incorrect
process_date amount reference
04FEB2022 100 trn01
04FEB2022 200 trn02
04FEB2022 300 trn03
04FEB2022 400 trn04
04FEB2022 500 trn05

Data Want
process_date amount reference
04FEB2022 100 trn01
04FEB2022 200 trn02
s_lassen
Meteorite | Level 14

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.

Solly7
Pyrite | Level 9
Hi Lassen, you have saved my life, your solutions works perfectly fine! I super appreaciate it

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 4 replies
  • 569 views
  • 3 likes
  • 3 in conversation