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.
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.