- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
try function DATATIME() , NOT system macro variable &sysdate &systime. %let timestamp=%sysfunc(datetime(),datetime.); %put ×tamp;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
;;;;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
edited.
I get the expected results in a bash script, of a 5 second difference
between the two time stamps. When I do this through SAS both time stamps
are equal to the time I execute the script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Second, what's the setting of XWAIT system option?
Third, why are you doing this with SAS? You could easily put those commands in a shell script instead.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
aware I could put this in a bash script. Secondly the team I look after use
x commands quite a lot in in their overnight SAS jobs.
I'll take a look at the XWAIT system option. Thank you.
##- Please type your reply above this line. Simple formatting, no
attachments. -##
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
command after the sleep.
x "stat >> /tmp/testfile";
##- Please type your reply above this line. Simple formatting, no
attachments. -##
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The fractionl difference you are seeing is the time for the first stat statement to write to standard out.
I think to illustrate what you are trying to see is something like this
x "touch /tmp/testfile";
x "stat /tmp/testfile >> /tmp/testfile";
x "sleep 5";
x "touch /tmp/testfile";
x "stat /tmp/testfile >> /tmp/testfile";
run;
File: `/tmp/testfile'
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: fd06h/64774d Inode: 22 Links: 1
Access: (0644/-rw-r--r--) Uid: (31898/ missas) Gid: ( 342/ mismeta)
Access: 2016-05-17 02:52:03.787098859 -0400
Modify: 2016-05-17 02:52:03.787098859 -0400
Change: 2016-05-17 02:52:03.787098859 -0400
File: `/tmp/testfile'
Size: 352 Blocks: 8 IO Block: 4096 regular file
Device: fd06h/64774d Inode: 22 Links: 1
Access: (0644/-rw-r--r--) Uid: (31898/ missas) Gid: ( 342/ mismeta)
Access: 2016-05-17 02:52:08.814236110 -0400
Modify: 2016-05-17 02:52:08.814236110 -0400
Change: 2016-05-17 02:52:08.814236110 -0400
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Aaaaaah....the touch command actually modifies the timestamp, I though just writing to the file would be enough. Thanks guys. 🙂