Is there a way to read time from one of the NIST servers into SAS directly?
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 -
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 ;
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)?
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.
which ntpdate - windows command?
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.
Ahhh thanks! I take it there are not any pre-installed windows utilities which can do this....
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 ;
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.