BookmarkSubscribeRSS Feed
Kirito1
Quartz | Level 8

I was working on SAS and I came to know that we can name our files as today's date using a pre-defined macro. But now I want to name my file as count of observations with file name and todays date. For Example: there were 3445 total observations and I want to keep my filename as Work with todays date.

So, the file name should be = 2023/01/04Work(Total Count = 3445).

The code in which filename was today's date is as follows so that you all can understand what I want. I want the exported file to be named as explained above.

 

proc export data=ABCData
outfile="/fileextension/Work\%sysfunc( today(), DDmmYY7 ).csv"
REPLACE
DBMS=CSV;
run;

Please, Help I want to learn how can I do that.

 

4 REPLIES 4
Patrick
Opal | Level 21

@Kirito1 wrote:

I was working on SAS and I came to know that we can name our files as today's date using a pre-defined macro. But now I want to name my file as count of observations with file name and todays date. For Example: there were 3445 total observations and I want to keep my filename as Work with todays date.

So, the file name should be = 2023/01/04Work(Total Count = 3445).

The code in which filename was today's date is as follows so that you all can understand what I want. I want the exported file to be named as explained above.


Stick for your filenames to letters, digits and the underscore. Using any other character is just asking for trouble with either SAS, your operating system or both.

 

Below some code illustrating how this could be done.

data _null_;
  call symputx('rowcnt',nobs);
  stop;
  set sashelp.class nobs=nobs;
run;

proc export
  data=sashelp.class
  outfile="c:\temp\myfile_&rowcnt._%sysfunc(today(),yymmddn8).csv"
  replace
  dbms=csv;
run;

 

Kirito1
Quartz | Level 8
I want to automate the process of naming file without even specifying date and row count its like a summary for the file before even opening a file. Its not useless If you think about it.
Patrick
Opal | Level 21

@Kirito1 wrote:
I want to automate the process of naming file without even specifying date and row count its like a summary for the file before even opening a file. Its not useless If you think about it.

Then what I've posted will work if the source table is a SAS table. If the source table is a database table then you will need to actually count the rows with code as below:

proc sql noprint;
  select count(*) format=f16. into :rowcnt trimmed
  from sashelp.class;
quit;
Kurt_Bremser
Super User

For any further automation, adding such a number to a filename will be an obstacle. Don't do it.

If people need that value, create a separate report and publish that (e.g. as HTML page via the SAS server's web server).

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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