BookmarkSubscribeRSS Feed
daearol
Calcite | Level 5

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.

13 REPLIES 13
Ksharp
Super User
try function  DATATIME() , NOT  system macro variable &sysdate &systime. 


%let timestamp=%sysfunc(datetime(),datetime.);

%put &timestamp;


Tom
Super User Tom
Super User

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.

angian
SAS Employee
Can you include your example program to illustrate the behavior you described?
daearol
Calcite | Level 5

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.

Tom
Super User Tom
Super User

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
;;;;

 

daearol
Calcite | Level 5
Hi Tom, I was checking the modify time stamp. To see when the file was last
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.
LinusH
Tourmaline | Level 20
First, I miss some end " and ; but that's probably typos in this post...?

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.
Data never sleeps
daearol
Calcite | Level 5
I'm doing this because I'm just learning how BASE SAS works, I'm fully
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. -##
angian
SAS Employee

 

xwait has nothing to do with this and only valid on Windows OS 🙂

http://support.sas.com/documentation/cdl/en/hostwin/67962/HTML/default/viewer.htm#n0xwt90ik8vxdrn137...

 

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.

daearol
Calcite | Level 5
It's going to change after a sleep because I append the output of the stat
command after the sleep.

x "stat >> /tmp/testfile";

##- Please type your reply above this line. Simple formatting, no
attachments. -##
angian
SAS Employee
The stat will not reflect the 5 seconds gap because the I/O of the append happens after the stat command.
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
angian
SAS Employee

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

daearol
Calcite | Level 5

Aaaaaah....the touch command actually modifies the timestamp, I though just writing to the file would be enough. Thanks guys. 🙂

suga badge.PNGThe SAS Users Group for Administrators (SUGA) is open to all SAS administrators and architects who install, update, manage or maintain a SAS deployment. 

Join SUGA 

Get Started with SAS Information Catalog in SAS Viya

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.

Discussion stats
  • 13 replies
  • 4218 views
  • 0 likes
  • 5 in conversation