As the first step in the decommissioning of sasCommunity.org the site has been converted to read-only mode.
Here are some tips for How to share your SAS knowledge with your professional network.
Adding timestamp to data set name
- From: SAS(r) Discussion  On Behalf Of sas 9 bi user
- Sent: Monday, October 27, 2008 1:16 AM
- To: SAS-L@LISTSERV.UGA.EDU
- Subject: Add Timestamp to dataset's name
Say I have
data b; set a; run;
I want to add a timestamp to B. When I try to do the below it errors out.
data b_%sysfunc(datetime()); set a; run;
This is what I would like B to be named as:
Note - Date/time is what sysfunc generates at time of call (so the above is at the time of this email writing for example).
From: Mike Rhoads
I see a couple of issues here:
1. By default the value displayed by datetime() is an unformatted number. You need to format it to make it understandable to humans.
2. The data set name format that you want contains characters that are invalid in SAS data set names (: and /).
While there are a number of possible ways to approach this, I would create a format using date-time directives (check the PROC FORMAT documentation) to produce a format that is readable but only contains acceptable characters, and use that with the %sysfunc call.
proc format; picture mydtfmt low-high = '%Y%0m%0d_%0I%0M%p' (datatype=datetime); run; data b_%unquote(%sysfunc(datetime(),mydtfmt.)); set sashelp.class; run;
NOTE: The data set WORK.B_20081027_0905AM has 19 observations and 5 variables.
See also: Macro_Variables_of_Date_and_Time