The SAS Output Delivery System and reporting techniques

Internet (NIST) time and SAS

Accepted Solution Solved
Reply
Contributor
Posts: 53
Accepted Solution

Internet (NIST) time and SAS

Is there a way to read time from one of the NIST servers into SAS directly?


Accepted Solutions
Solution
‎09-19-2013 10:16 AM
SAS Employee
Posts: 25

Re: Internet (NIST) time and SAS

Doug -

Please try the following:

filename foo pipe "/sbin/ntpdate -q time.nist.gov" ;

data _null_;

infile foo firstobs=2 ;

input ;

day=scan(_infile_,1," ") ;

mon=scan(_infile_,2," ") ;

time=scan(_infile_,3," ") ;

ntp=strip(day)||strip(mon)||strip(time) ;

ntptime=input(ntp,datetime.) ;

put ntptime= datetime. ;

run ;

View solution in original post


All Replies
Solution
‎09-19-2013 10:16 AM
SAS Employee
Posts: 25

Re: Internet (NIST) time and SAS

Doug -

Please try the following:

filename foo pipe "/sbin/ntpdate -q time.nist.gov" ;

data _null_;

infile foo firstobs=2 ;

input ;

day=scan(_infile_,1," ") ;

mon=scan(_infile_,2," ") ;

time=scan(_infile_,3," ") ;

ntp=strip(day)||strip(mon)||strip(time) ;

ntptime=input(ntp,datetime.) ;

put ntptime= datetime. ;

run ;

Contributor
Posts: 53

Re: Internet (NIST) time and SAS

The program returns the following:

 

Stderr output:

The system cannot find the path specified.

Could this be a firewall issue on my end or a SAS issue (perhaps both)?

SAS Employee
Posts: 25

Re: Internet (NIST) time and SAS

Doug -

You'll need to verify the path to the ntpdate command on your system - not to mention verify that it is installed.

The command:   which ntpdate

will show either the correct path to the command, or report that it is not found among the paths included in the $PATH environment variable.

Contributor
Posts: 53

Re: Internet (NIST) time and SAS

which ntpdate - windows command?

SAS Employee
Posts: 25

Re: Internet (NIST) time and SAS

Sorry, I generally think of NTP as being Unix/Linux.

You'll probably need to install NTP: http://www.satsignal.eu/ntp/setup.html

And then modify the SAS code to call the appropriate Windows command.

Contributor
Posts: 53

Re: Internet (NIST) time and SAS

Ahhh thanks! I take it there are not any pre-installed windows utilities which can do this....

SAS Employee
Posts: 25

Re: Internet (NIST) time and SAS

This should do it. Note this returns GMT, so you'll need to adjust for your time zone.

filename foo http "http://www.time.gov/timezone.cgi?Eastern/d/-5/java" debug ;

data _null_ ;

length p1 $50 ;

infile foo ;

input ;

put _infile_;

if index(_infile_, "NISTSendTime") then do ;

ind1=index(_infile_,'"') ;

p1=substr(_infile_,ind1+1,length(_infile_)-ind1-3) ;

mon=substr(scan(p1,1," "),1,3) ;

date=scan(p1,2,", ") ;

time=scan(p1,4," ") ;

year=put(year(today()),4.);

now=strip(date)||strip(mon)||year||' '||strip(time);

nistime=input(now, datetime.) ;

sastime=datetime();

put nistime= datetime. ;

put sastime= datetime. ;

stop ;

end ;

run ;

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 649 views
  • 7 likes
  • 2 in conversation