Help using Base SAS procedures

dirlistwin

Reply
Contributor
Posts: 65

dirlistwin

I looking at grabbing some files based the modification date and trying this with dirlistwin. How do I get dirlistwin to recognize the modification date. My goal is to grab files that are less than 5 day old.

Thanks,
Nick
Trusted Advisor
Posts: 2,113

Re: dirlistwin

You will need to modify the macro to get the date modified rather than the date created. Use the dir /? command to see the syntax you need to change for your version of windows. Then modify the first filename command in the macro.
Contributor
Posts: 65

Re: dirlistwin

Thanks. I got the macro edited so that it will read the correct date. I want to incorporate the date filter and I don't want to hardcode the dates. Do you know a way to do something like this:

%dirlistwin (D:/temp/tmp/images,
OUT=work.temp,
REPORT=N,
MINDATE = "&sysdate."d - 5,
MAXDATE = "&sysdate."d
)

The directory that I'm checking has MANY files and I only want the files that are 5 days old.
Valued Guide
Posts: 632

Re: dirlistwin

In the macro world you will have to force the conversion of the data constant.
One way to do this is with the PUTN function.
[pre]%macro test(now, then);
%put now &now;
%put then &then;
%mend test;
%test(%sysfunc(putn("&sysdate"d,6.)), %eval(%sysfunc(putn("&sysdate"d,6.))-5))
[/pre]
Frequent Contributor
Posts: 106

Re: dirlistwin

Just as an aside: using %sysevalf gives you the date value immediately.

Try
[pre]
%put %sysevalf("&sysdate"d) ;
%put %sysevalf("&sysdate"d+0) ;
%put %sysevalf("&sysdate"d-5) ;
[/pre]

When I want to edit the date value in macro logic I tend to use the intnx function like in
[pre]
%let my_date = %sysfunc(intnx(day,"&sysdate"d,-5),ddmmyyp10.) ;
[/pre]
(where I know that syntactically the dot after the format name ain't needed)
Valued Guide
Posts: 632

Re: dirlistwin

Good suggestion on the use of %SYSEVALF. Much simpler.
Ask a Question
Discussion stats
  • 5 replies
  • 300 views
  • 0 likes
  • 4 in conversation