DATA Step, Macro, Functions and more

Assigning value to macro variable based on weekday to process data

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 12
Accepted Solution

Assigning value to macro variable based on weekday to process data

Hello 

 

I want to specify folder date in the program. I receive the data on Weekdays at night and run the program early next morning. So, the folder date is always like this:

 

Processing data on Tue        --------------     Date of Mon

Processing data on Wed       --------------    Date of Tue

Processing data on Thur       --------------    Date of Wed

Processing data on Fri          --------------    Date of Thu

Processing data on Mon       --------------    Date of Fri(Last)              /*Facing problem in this one*/

 

I have written macro variable where it reads in the previous data dates. 

 

%LET FOLDER_NAME = %SYSFUNC(INTNX(WEEKDAY, %SYSFUNC(TODAY()),-1,E),YYMMDDN8.);

 

So, If I process the data on 20170725, the folder date would be 20170724. But how should I include logic in this one for processing data on Monday. So, if the data is processed on monday of any given week, it should take in the date of last friday.

 

Thanks

Chandan Mishra


Accepted Solutions
Solution
3 weeks ago
Super User
Posts: 17,840

Re: Assigning value to macro variable based on weekday to process data

The alignment parameter is messing up your calculation.

Remove it.

 
 1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 59         
 60         %let testdate = '24Jul2017'd;
 61         %LET FOLDER_NAME = %SYSFUNC(INTNX(WEEKDAY, &testdate,-1),YYMMDDN8.);
 62         %put &folder_name.;
 20170721
 63         
 64         OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 76    

View solution in original post


All Replies
Super User
Posts: 17,840

Re: Assigning value to macro variable based on weekday to process data

Did you check the output? Using INTNX with the WEEKDAY should accomplish this, is it not? If so, post an example of how it isn't working.

Occasional Contributor
Posts: 12

Re: Assigning value to macro variable based on weekday to process data

So, If I used this code for Monday 24th July, 2017, it is giving me value of 20170723. Rather I want the value to be  20170721 i.e. Friday.

 

 

Thanks

Chandan Mishra

 

 

Solution
3 weeks ago
Super User
Posts: 17,840

Re: Assigning value to macro variable based on weekday to process data

The alignment parameter is messing up your calculation.

Remove it.

 
 1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 59         
 60         %let testdate = '24Jul2017'd;
 61         %LET FOLDER_NAME = %SYSFUNC(INTNX(WEEKDAY, &testdate,-1),YYMMDDN8.);
 62         %put &folder_name.;
 20170721
 63         
 64         OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 76    
Occasional Contributor
Posts: 12

Re: Assigning value to macro variable based on weekday to process data

 Thank you so much for providing the solution. 

 

Thanks

Chandan Mishra

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 84 views
  • 0 likes
  • 2 in conversation