BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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
10 REPLIES 10
ArtC
Rhodochrosite | Level 12
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)
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.
data_null__
Jade | Level 19
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]
deleted_user
Not applicable
%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?
deleted_user
Not applicable
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?
data_null__
Jade | Level 19
Are you wanting to add the date stamp to each SAS data set name this is added to the date stamped XPORT library?
deleted_user
Not applicable
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?
data_null__
Jade | Level 19
> 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.
deleted_user
Not applicable
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?
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
See reply to "How do we handle..." here:

http://support.sas.com/forums/thread.jspa?threadID=10841 Message was edited by: sbb

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 10 replies
  • 2412 views
  • 0 likes
  • 4 in conversation