Import a file from 2 days ago on Mondays but a file from current day Tue-Fri

Reply
Regular Learner
Posts: 1

Import a file from 2 days ago on Mondays but a file from current day Tue-Fri

I am trying to import 1 file name on Mondays and another file name on Tue-Fridays.  

 

For example, on Monday I want to import the file from Saturday but on Tue-Fri I want to import the file for the current day.  


This is what I am trying.  It doesn't  seem to read the &today macro at all.  

 

Code: 

 

%let today=%sysfunc(putn(%sysfunc(date()),yymmddn8.));
%let today2=%sysfunc(PUTN(%eval(%sysfunc(date()) - 2), yymmddn8.));

 


%macro setdate(date);
%let date= weekday(today());
%if &date = 2 %then
%do;
proc import out=M_IMPORT 

datafile="<path>/test/M_Daily_Admissions_&today2..csv"

dbms=csv replace;
datarow=2;
getnames=no;
run;
%end;
%else %if &date <> 2 %then
%do;
proc import out=M_IMPORT 

datafile="/<path>/test/M_Daily_Admissions_&today..csv"

dbms=csv replace;
datarow=2;
getnames=no;
run;
%end;
%mend setdate;

Super User
Posts: 6,362

Re: Import a file from 2 days ago on Mondays but a file from current day Tue-Fri

This might not cover everything, but it's the right place to start.  This statement doesn't do what you expect:

 

%let date= weekday(today());

 

While it runs without error, it assigns &DATE a 16-character value (the exact characters you see to the right of the equal sign, with no functions being executed). 

 

As you did in several earlier cases, you need to apply %SYSFUNC to get macro language to carry out DATA step functions:

 

%let date = %sysfunc(weekday(%sysfunc(today())));

 

Ask a Question
Discussion stats
  • 1 reply
  • 59 views
  • 0 likes
  • 2 in conversation