BookmarkSubscribeRSS Feed
umashankersaini
Quartz | Level 8

Hi Team,

 

I need to generate outfile from proc eport with running serial number if file already exist with same date.

 

 

 

sample code to generate file name with date :

 

%Let fname=%sysfunc(today(),mmddyyn8.);

%let file=uma;

 

Proc export data=work.test

outfile="C:\Desktop\&file&fname.01.txt"

dbms=csv;

quit;

 

 

Code would generate file : uma0927201601.txt

 

I am looking for that "01" in filename should get change  to 02 and 03....if i generate the same file today itself.

 

Regards,

Uma Shanker Saini

3 REPLIES 3
Kurt_Bremser
Super User

This document describes how to obtain a directory listing using only SAS functions. You can then subset on the first part of your filename, and then iterate to the last found file, add 1, and create a new filename.

user24feb
Barite | Level 11

Filename Txt_List Pipe 'dir "C:\ ... \*.txt" /b'; 
Data _NULL_;
  Infile Txt_List TruncOver;
  Input Filename $100.;
  * If Find(Filename,<Currentdatestring>);
  Counter=Input(Substr(Filename,Find(Filename,'.')-2,2),2.)+1;
  Call SymputX('Counter',Counter);
Run;
%Put **&Counter.***;
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Am not sure that is the best approach.  If you absolutely have to create separate files (and that would be my first pushback), and they abosultely have to have data in the filename (again, another pushback), then why not use a full date/timestamp and forget about incrementals?  You can simply export your data as:

proc export data=work.test 
  outfile="c:\desktop\uma%sysfunc(date()date.)_%sysfunc(time(),tod8.).csv"
  dbms=csv;
quit;

Note, its a good idea to have the file extension show what the file contains, txt = text, csv= csv.

 

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 3 replies
  • 981 views
  • 0 likes
  • 4 in conversation