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 2024

Innovate_SAS_Blue.png

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. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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