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;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.