I currently receive a daily file with an odd naming format. The file name format is CFXTRN(9.5.2019), no extension. I need to change the name to CFXTRN0905. I use the code below to change the name which works great, except when it is a 1 digit day of the month, such as 9/5/2019. How can I update my code so that it works for 1 or 2 digit day of the month?
DATA STEP2;
DATE3 = PUT("&DATE2.",$10.);
DATE4 = Substr(DATE3,Verify(DATE3,'0'));
CALL symput('FILEINA',COMPRESS("CFXTRN" !! "(" !! date4 !! ")"));
CALL SYMPUT('FILEOUT',CAT("CFXTRN","&DATE1."));
RUN;
DATA _NULL_;
FILECFX=RENAME("&SOURCE.\&FILEINA","&SOURCE.\&FILEOUT.","FILE");
RUN;
Please try the below code
DATA STEP2;
DATE3 = put(input("&sysdate9.",date9.),ddmmyy10.);
DATE3_ = prxchange('s/(0)(\d{1,2}\.)(0)(\d{1,2}\.)(\d{4})/$2$4$5/',-1,strip(tranwrd(put(input("&sysdate9.",date9.),ddmmyy10.),'/','.')));
DATE4 = compress(Substr(DATE3,1,5),'/');
CALL symput('FILEINA',COMPRESS("CFXTRN" !! "(" !! DATE3_ !! ")"));
CALL SYMPUT('FILEOUT',CAT("CFXTRN",DATE4));
RUN;
%put &FILEINA &FILEOUT;
Please try the below code
DATA STEP2;
DATE3 = put(input("&sysdate9.",date9.),ddmmyy10.);
DATE3_ = prxchange('s/(0)(\d{1,2}\.)(0)(\d{1,2}\.)(\d{4})/$2$4$5/',-1,strip(tranwrd(put(input("&sysdate9.",date9.),ddmmyy10.),'/','.')));
DATE4 = compress(Substr(DATE3,1,5),'/');
CALL symput('FILEINA',COMPRESS("CFXTRN" !! "(" !! DATE3_ !! ")"));
CALL SYMPUT('FILEOUT',CAT("CFXTRN",DATE4));
RUN;
%put &FILEINA &FILEOUT;
Thanks! That works. I would've never been able to do the DATE3_ code. It might as well have been written in wingdings, but I am very grateful for your help.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.