Hi,
i want to write a macro that will infile my txt (name of the file is based in a date, example: aaa_20170929) file on the last working day of the month.
For example, last working day of september was 29, last day of october is 31.
thank you in advance.
So, step one get date value, second step use to import, rough guess:
data _null_; prev=intnx('',today(),-1,'end'); /* Moves back a month */ if weekday(prev)=1 then prev=prev-2; /* sunday so remove 2 */ if weekday(prev)=7 then prev=prev-1; /* sat so -1 */ call symputx('dt',put(prev,yymmdd10.)); run; data want; infile "c:\abc_&dt..txt"; ... run;
Assuming you don't expect us to provide the full code free of charge: What's the question/problem you need help with? What have you done already?
In case you don't know how to align a date to the end of month: Look up the intnx() function in the docu.
So, step one get date value, second step use to import, rough guess:
data _null_; prev=intnx('',today(),-1,'end'); /* Moves back a month */ if weekday(prev)=1 then prev=prev-2; /* sunday so remove 2 */ if weekday(prev)=7 then prev=prev-1; /* sat so -1 */ call symputx('dt',put(prev,yymmdd10.)); run; data want; infile "c:\abc_&dt..txt"; ... run;
%let year=2017;
%let month=9;
%let want=%sysfunc(intnx(weekday,%sysfunc(mdy(&month+1,1,&year))-1,0),yymmddn.);
%put &want;
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.