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

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Jagadishkatam
Amethyst | Level 16

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,
Jag

View solution in original post

2 REPLIES 2
Jagadishkatam
Amethyst | Level 16

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,
Jag
arjessup
Fluorite | Level 6

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.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 881 views
  • 1 like
  • 2 in conversation