I have written a lot of macros over the past that utilize pipe commands as in the code box below. The date from the dir commands has always been in MM/DD/YYYY for me. This has worked fine for quite some time because everyone that uses my code is either in the US or India, and we have all had our computers set to this format. However, we have been bringing in users from the UK, and they all set their systems to be DD/MM/YYYY. When they run my code, this pipe command swaps the day and month, and then I get invalid notes in my log because they don't consider 29/04/2025 to be a valid date. Visually, I can tell that this is April 29, but since my code is set up to read it as MM/DD/YYYY, it doesn't know what the 29th month is.
With all that background, is there a way to easily tell which format the value is in? I can set up some IF statements such that if the first 2 digits are greater than 12, then I know it's in DD/MM/YYYY format, or if the second 2 digits are greater than 12, then I know it's in MM/DD/YYYY format. However, if both are less than or equal to 12, I won't know. 04/03/2025 could be March 4 or April 3. Has anyone dealt with this scenario before?
filename SASlist pipe "dir /t:w &datapath.\*.sas7bdat";
data datadir;
infile SASlist dlm="¬";
length buff $2000;
input buff;
if _n_>3 & index(buff,"File")=0 & index(buff,"Dir")=0 then do;
date=input(scan(buff,1,''),mmddyy10.);
file=scan(buff,-1,'');
dset=upcase(scan(file,1,'.'));
end;
format date date9.;
run;
... View more