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: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

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