Hello all,
I'm not very knowledgeable about SAS so please forgive the beginner nature of this question.
I need to create a SAS XPT file in SAS 9.1.3 the has the date and time at the end of the filename (e.g. "CR845_CLIN2001_LB_19AUG2015_11:44"). I have a script that includes the date but I have no idea how to add the time. Here are the lines of code that I think need to be changed (these are not all in a block, they're just the lines that reference the filname)_:
Any help appreciated!
Comments/Questions
1) Don't use ddMONyyyy format for a date stamp in a filename. It will not sort properly. Use YYYYMMDD.
2) You cannot use colon (;) in a filename on a Windows drive since it is reserved for drive letter prefixes.
3) Do you want the date/time that SAS started (ie &SYSDATE9 and &SYSTIME) or the current time (datetime(), or date() and time() function calls)?
4) Do you want to include the date/time in both the XPORT filename and the member name?
5) Your first data step has no actual code.
6) You do not have any code to actually create the XPORT format version of the dataset.
Here is a version of your code that will use YYYYMMDD_HHMM formatted suffix on the member name and the XPORT filename.
%let dir=\\Acmshares2\clntrial\DataMgt\C1845\DataTransfer\Data\Sent ;
%let fileBaseName=CR845_CLIN2001_LB;
%let dt=%sysfunc(date(),yymmddn8);
%let dt=&dt._%sysfunc(compress(%sysfunc(time(),time5),:));
libname LABDATA "&dir\SAS7BDAT";
libname LB "&dir\LB";
libname XPORTOUT xport "&dir\SAS\&fileBaseName._&dt..xpt";
data LABDATA.&fileBaseName._&dt (COMPRESS=YES);
....
run;
data LB.LB;
set LABDATA.&fileBaseName._&dt;
run;
proc contents data = LABDATA.&fileBaseName._&dt varnum;
run;
The time when the SAS process was started is provided by the automatic macro variable &systime: SAS(R) 9.2 Macro Language: Reference
The SAS 9.2 reference is of limited help to me here because we're using SAS 9.1.3, as mentioned in my OP. I have no choice or control over this - whatever solution I use has to work in SAS 9.1.3 on Windows.
Just checked:
&systime is also present in SAS 9.1.3.
NOTE: Copyright (c) 2002-2003 by SAS Institute Inc., Cary, NC, USA.
NOTE: SAS (r) 9.1 (TS1M3)
Licensed to xxxxxxxxxx AIX, Site xxxxxxxxxxx.
NOTE: This session is executing on the AIX 5.3 platform.
NOTE: SAS 9.1.3 Service Pack 4
You are running SAS 9. Some SAS 8 files will be automatically converted
by the V9 engine; others are incompatible. Please see
http://support.sas.com/rnd/migration/planning/platform/64bit.html
PROC MIGRATE will preserve current SAS file attributes and is
recommended for converting all your SAS libraries from any
SAS 8 release to SAS 9. For details and examples, please see
http://support.sas.com/rnd/migration/index.html
This message is contained in the SAS news file, and is presented upon
initialization. Edit the file "news" in the "misc/base" directory to
display site-specific news and information in the program log.
The command line option "-nonews" will prevent this display.
NOTE: SAS initialization used:
real time 8.99 seconds
cpu time 0.17 seconds
NOTE: Unable to open SASUSER.REGSTRY. WORK.REGSTRY will be opened instead.
NOTE: All registry changes will be lost at the end of the session.
WARNING: Unable to copy SASUSER registry to WORK registry. Because of this,
you will not see registry customizations during this session.
NOTE: Unable to open SASUSER.PROFILE. WORK.PROFILE will be opened instead.
NOTE: All profile changes will be lost at the end of the session.
NOTE: This SAS session is using a registry in WORK. All changes will be
lost
at the end of this session.
NOTE: This SAS session is using a registry in WORK. All changes will be
lost
at the end of this session.
NOTE: AUTOEXEC processing beginning; file is $HOME/autoexec.sas.
NOTE: AUTOEXEC processing completed.
NOTE: This SAS session is using a registry in WORK. All changes will be
lost at the end of this session.
1 %put &sysdate;
20AUG15
2 %put &systime;
14:36
Comments/Questions
1) Don't use ddMONyyyy format for a date stamp in a filename. It will not sort properly. Use YYYYMMDD.
2) You cannot use colon (;) in a filename on a Windows drive since it is reserved for drive letter prefixes.
3) Do you want the date/time that SAS started (ie &SYSDATE9 and &SYSTIME) or the current time (datetime(), or date() and time() function calls)?
4) Do you want to include the date/time in both the XPORT filename and the member name?
5) Your first data step has no actual code.
6) You do not have any code to actually create the XPORT format version of the dataset.
Here is a version of your code that will use YYYYMMDD_HHMM formatted suffix on the member name and the XPORT filename.
%let dir=\\Acmshares2\clntrial\DataMgt\C1845\DataTransfer\Data\Sent ;
%let fileBaseName=CR845_CLIN2001_LB;
%let dt=%sysfunc(date(),yymmddn8);
%let dt=&dt._%sysfunc(compress(%sysfunc(time(),time5),:));
libname LABDATA "&dir\SAS7BDAT";
libname LB "&dir\LB";
libname XPORTOUT xport "&dir\SAS\&fileBaseName._&dt..xpt";
data LABDATA.&fileBaseName._&dt (COMPRESS=YES);
....
run;
data LB.LB;
set LABDATA.&fileBaseName._&dt;
run;
proc contents data = LABDATA.&fileBaseName._&dt varnum;
run;
1) Don't use ddMONyyyy format for a date stamp in a filename. It will not sort properly. Use YYYYMMDD.
Although I agree, the client specifies the date format, I have no leeway to change it.
2) You cannot use colon (;) in a filename on a Windows drive since it is reserved for drive letter prefixes.
Makes sense and explains why formats with a colon were rejected.
3) Do you want the date/time that SAS started (ie &SYSDATE9 and &SYSTIME) or the current time (datetime(), or date() and time() function calls)?
They want the time the file was created.
4) Do you want to include the date/time in both the XPORT filename and the member name?
I don't know what this means - as I said, I have very limited experience with SAS.
5) Your first data step has no actual code.
These are just the lines in the template script I was given that make use of the date. I figured they all needed to be changed to include the time as well.
6) You do not have any code to actually create the XPORT format version of the dataset.
That code is in the template script that I was given. The lines of code I provided are only the ones that use the date. I was told to modify them all to have the date and time.
I'll give your code a try and see if I can get it working in the context of what got dropped in my lap. Thanks!
I would add to the above very good solutions the question why. Anyone using version control will not like you for putting "data" in the filename. For two reasons, one it makes it slightly more difficult to get to, and secondly everytime the file is received, it is 'different' in terms of the version control system. This looks to me like another harkening back to the old days where version control systems were not used, in much the same way that the use of XPT files is still around, even regulators are now moving away from supporting that file format. Look into XML for a file transfer, or CSV at least.
Why = because our clients control the format of the filenames according to their preference, and this client specified a filename in the format "CR845_CLIN2001_LB_DATE_TIME". There is no version control on the transport files because a completely new one is created every time the process is run.
I'm sure your advice would be helpful to a developer who had some influence or choice in these matters. In this case, I don't.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.