DATA Step, Macro, Functions and more

update a xpt file name with the sysdate

Reply
N/A
Posts: 0

update a xpt file name with the sysdate

I have set up a sas program to runn automatically and create an XPT file. How can I update this xpt file name to have current date in the name in order to identify the xpt ?
Any suggestion would be helpful
Valued Guide
Posts: 632

Re: update a xpt file name with the sysdate

When you create the name of a data set or file say xxxx include the macro variable &sysdate (I prefer &sysdate9) in the name. Something like:

xxxx&sysdate9

If an extension is needed

xxxx&sysdate9..xpt (notice the double dot)
Super Contributor
Super Contributor
Posts: 3,174

Re: update a xpt file name with the sysdate

Also, any SAS date format can be generated using %SYSFUNC with PUTN as shown below:

%let today_formatted = %sysfunc(putn(%sysfunc(today()),yymmddn8.));
%put _user_;

Scott Barry
SBBWorks, Inc.
Respected Advisor
Posts: 3,777

Re: update a xpt file name with the sysdate

Too many %SYSFUNCs. The often neglected optional second parameter is

[pre]
4594 %let today_formatted = %sysfunc(today(),yymmddn8.);
4595 %put _user_;
GLOBAL TODAY_FORMATTED 20100817
[/pre]
N/A
Posts: 0

Re: update a xpt file name with the sysdate

%let today_formatted = %sysfunc(today(),date9.); is the format I am using, but how can I assign this in the trfile where it has to be created?
N/A
Posts: 0

Re: update a xpt file name with the sysdate

Thanks, but how do I assign this to the filename? for eg xpt name XXXXXX_&sysdate9...xpt should be create in filename trfile 'C:\SAS\XXXXXX_&sysdate9...xpt. Is this possible or there is some other means of doing it?
Respected Advisor
Posts: 3,777

Re: update a xpt file name with the sysdate

Are you wanting to add the date stamp to each SAS data set name this is added to the date stamped XPORT library?
N/A
Posts: 0

Re: update a xpt file name with the sysdate

No. only to the XPT file that will be created using cport. for eg my code is

%let today = %sysfunc(today(),date9.);
libname trData 'P:\SAS Programs\Datasets';
filename trFile 'P:\SAS Programs\Data\Datasets\Lm-LLO-E7-07_EXTRACT_&today...xpt' ;


proc cport library=trData file=trFile;
run;

Is my code correct for creating an XPT with date stamp?
Respected Advisor
Posts: 3,777

Re: update a xpt file name with the sysdate

> filename trFile 'P:\SAS Programs\Data\Datasets\Lm-LLO-E7-EXTRACT_&today...x> pt' ;

You need to use DOUBLE quotes so &today will be resolved.
N/A
Posts: 0

Re: update a xpt file name with the sysdate

Thanks a lot. I just missed to try that simple step!!!! Thanks, anyways.

One more question:
How do we handle the missing values in a field(VSTMD) thats a varchar datatype and that has to be written into a numeric SAS date field? Since it is a "null" value, SAS considers as both character and numeric variable. How can this be resolved?
Super Contributor
Super Contributor
Posts: 3,174

Re: update a xpt file name with the sysdate

See reply to "How do we handle..." here:

http://support.sas.com/forums/thread.jspa?threadID=10841 Message was edited by: sbb
Ask a Question
Discussion stats
  • 10 replies
  • 368 views
  • 0 likes
  • 4 in conversation