BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Doug
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
TimB_SAS
SAS Employee

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

7 REPLIES 7
TimB_SAS
SAS Employee

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 ;

Doug
Calcite | Level 5

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)?

TimB_SAS
SAS Employee

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.

Doug
Calcite | Level 5

which ntpdate - windows command?

TimB_SAS
SAS Employee

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.

Doug
Calcite | Level 5

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

TimB_SAS
SAS Employee

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 ;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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