BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Kirito1
Quartz | Level 8

I was working on SAS I wanted to name file something like below:

proc export data=CUSTAVG
outfile="/Outfile_file/Transactions \%sysfunc( today(), date9 ).csv"
REPLACE
DBMS=CSV;
run;

But now I want number of records in the files, with file name.

For Example my file name is transaction that has 55 records and I want yesterdays date to be attached with filename.

Something like this : Transactions 21FEB2023 (55)

 

Can anyone help, How can I do that in this existing code. I know some macro should be build.

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Three suggestions:

Use a date in the form of YYYYMMDD. That way system sorting tools will show the sets in calendar date order.

Second, do not use special characters like () in file names.

Third, always start an output file name/path with the drive (windows) or root of a mount point for a drive.

 

One way to may a suggested file

data _null_;
   set CUSTAVG (obs=1) nobs=c;
   call symputx('trans_n',c);
   call symputx('yesterday',put(intnx('day',today(),-1),yymmddn8.));
run;


proc export data=CUSTAVG
outfile="/Outfile_file/Transactions&yesterday._&trans_n..csv"
REPLACE
DBMS=CSV;
run;

The NOB= option on the set statement returns the number of observations in the data set. This is just one way to get the info but may be the shortest. The Call Symputx places the value using a default format into a macro variable. Since already using a data step add in another step to use the INTNX function to get the previous day and use the YYMMDDN.8 format which generates values like 20230222.

The . is used to indicate the end of a macro variable. So when there is a macro variable next to the dot in an extension you need to add one so that the macro processor does not use the one intended for the extension.

 

If you really need to use less friendly dates or add () change the format in the Call Symputx and and the () to the name around the Trans_n macro variable.

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

Adding the number of transactions into a file name just makes the file more difficult to find, and in my opinion, the best thing to do would be to leave the number of transactions out of the file name. What is the benefit of adding it in?

 

You asked the same question in your earlier thread, and so by asking again, you get the same advice.

--
Paige Miller
LinusH
Tourmaline | Level 20

You can extract no records in your input data set using dictionary.tables:

Untested:

proc sql;
   select nobs into: nrecs
      from dictionary.tabeles
      where memname = "CUSTAVG"
   ;
quit;

 

Data never sleeps
ballardw
Super User

Three suggestions:

Use a date in the form of YYYYMMDD. That way system sorting tools will show the sets in calendar date order.

Second, do not use special characters like () in file names.

Third, always start an output file name/path with the drive (windows) or root of a mount point for a drive.

 

One way to may a suggested file

data _null_;
   set CUSTAVG (obs=1) nobs=c;
   call symputx('trans_n',c);
   call symputx('yesterday',put(intnx('day',today(),-1),yymmddn8.));
run;


proc export data=CUSTAVG
outfile="/Outfile_file/Transactions&yesterday._&trans_n..csv"
REPLACE
DBMS=CSV;
run;

The NOB= option on the set statement returns the number of observations in the data set. This is just one way to get the info but may be the shortest. The Call Symputx places the value using a default format into a macro variable. Since already using a data step add in another step to use the INTNX function to get the previous day and use the YYMMDDN.8 format which generates values like 20230222.

The . is used to indicate the end of a macro variable. So when there is a macro variable next to the dot in an extension you need to add one so that the macro processor does not use the one intended for the extension.

 

If you really need to use less friendly dates or add () change the format in the Call Symputx and and the () to the name around the Trans_n macro variable.

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 646 views
  • 1 like
  • 4 in conversation