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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;

View solution in original post

4 REPLIES 4
Patrick
Opal | Level 21

@Jedrzej

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.

Jedrzej
Obsidian | Level 7
i'm getting txt files from monday to friday. I want to infile just the last file that exist of the previous month, every first day of the current month.

So the problem is that the names of files are based on the date that they were generated and if the last day of the month will be Sunday there won't be any file.

I need a macro that will check txt files from the previous month and infile the last one that exist.
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;
Ksharp
Super User
%let year=2017;
%let month=9;

%let want=%sysfunc(intnx(weekday,%sysfunc(mdy(&month+1,1,&year))-1,0),yymmddn.);

%put &want;

sas-innovate-2024.png

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.

 

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
  • 1043 views
  • 1 like
  • 4 in conversation