Hello, I'm new to SAS Administration and SAS in general. I'm teaching myself BASE SAS and I've learned recently that you can issue OS commands. However I've come across something strange that I can't find answers to. When I run the stat command(should mention I'm working within a linux environment), the time stamps are just plane wrong, compared to when I issue the command normally through the bash prompt.
For example, I touch a file with an x command, run the stat command and appened it to the new file, I'll then sleep for a while and the run another stat command and then append it to the file.
Both time stamps are equal to the time I execute the SAS script, where really I'd expect the second timestamp to be equal to the amount of time after the sleep command has been issued. Is this black magic?
Not sure if it's relavent, but I'm running SAS 9.3.
try function DATATIME() , NOT system macro variable &sysdate &systime. %let timestamp=%sysfunc(datetime(),datetime.); %put ×tamp;
Post an example that replicates the problem.
SAS is not changing your system clock, but perhaps you are looking at the wrong things.
For example if you are trying to look at the status of the LOG file generated by a running SAS program you need to remember that SAS buffers its writes to the disk.
Hi sorry, it's this:
x "touch /tmp/testfile
x "stat >> /tmp/testfile
x "sleep 5"
x "stat >> /tmp/testfile"
1st output:
Access: 2016-05-11 16:30:57.956598140 +0100
Modify: 2016-05-11 16:30:57.956598140 +0100
Change: 2016-05-11 16:30:57.956598140 +0100
2nd output after the sleep:
Access: 2016-05-11 16:30:57.956598140 +0100
Modify: 2016-05-11 16:30:57.971598140 +0100
Change: 2016-05-11 16:30:57.971598140 +0100
>For example if you are trying to look at the status of the LOG file generated by a running SAS program you need to remember that SAS buffers its writes to the disk.
Okay but how does that make sense if you're pausing the script for an arbitrary amount of time? I've even tried sleeping using a SAS function, but all the x commands appear execute regardless.
Sorry for the late reply.
I don't think you are using the STAT command properly. What are you asking it to tell you the STAT of? You seem to be missing the argument for this command.
I find it works much better to call your OS commands using an INFILE pipe instead of using X, SYSTEM() or %SYSEXEC().
That way you can read the output and figure out if the operating system is trying the send you any messages.
%let path=%sysfunc(pathname(work));
data _null_;
input;
cmd=resolve(_infile_);
infile cmd pipe filevar=cmd end=eof;
do while (not eof);
input;
put _infile_;
end;
cards;
touch &path/testfile.txt
stat &path/testfile.txt
sleep 5
touch &path/testfile.txt
stat &path/testfile.txt
;;;;
xwait has nothing to do with this and only valid on Windows OS 🙂
I don’t understand from your example why you think the STAT info of `/tmp/testfile' is going to change after a sleep.
If you provide the exact command line in the UNIX shell with output I will show you that SAS will do the same using X. You first need to get your commands correct in UNIX.
If I run this in a shell I get the same expected results and consistent with SAS
touch /tmp/testfile
stat /tmp/testfile >> /tmp/testfile
sleep 5s
stat /tmp/testfile >> /tmp/testfile
File: `/tmp/testfile'
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: fd06h/64774d Inode: 39 Links: 1
Access: (0644/-rw-r--r--) Uid: (31898/ missas) Gid: ( 342/ mismeta)
Access: 2016-05-17 03:30:34.054873628 -0400
Modify: 2016-05-17 03:30:34.054873628 -0400
Change: 2016-05-17 03:30:34.054873628 -0400
File: `/tmp/testfile'
Size: 352 Blocks: 8 IO Block: 4096 regular file
Device: fd06h/64774d Inode: 39 Links: 1
Access: (0644/-rw-r--r--) Uid: (31898/ missas) Gid: ( 342/ mismeta)
Access: 2016-05-17 03:30:34.054873628 -0400
Modify: 2016-05-17 03:30:34.057873708 -0400
Change: 2016-05-17 03:30:34.057873708 -0400
Aaaaaah....the touch command actually modifies the timestamp, I though just writing to the file would be enough. Thanks guys. 🙂
The SAS Users Group for Administrators (SUGA) is open to all SAS administrators and architects who install, update, manage or maintain a SAS deployment.
SAS technical trainer Erin Winters shows you how to explore assets, create new data discovery agents, schedule data discovery agents, and much more.
Find more tutorials on the SAS Users YouTube channel.