BookmarkSubscribeRSS Feed
shellp55
Quartz | Level 8
Hi

I am using SAS 9.1 and importing a .txt file using infile and input statements. I am then exporting the file to an MS-Access database.

I've got everything figured out except the time fields. Each time field in the file is in a time increment of a 24 hour clock but without the colon i.e. 2130, 1055, 1544. How do I import so that SAS recognizes it as a time? What format do I then use upon export?

Thanks for any and all assistance.
6 REPLIES 6
ChrisNZ
Tourmaline | Level 20
No std informat i think to read such a time. You have to tweak it a bit.

x='2130';
sastime=input(x,2.)*3600+input(substr(x,3,2),2.)*60;
or
sastime=input( substr(x,1,2)||':'||substr(x,3,2)||':00', time.);

The export format will depend on what Access wants. time. or hhmm. would seem adequate.
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
For more structured support, use the HMS function after reading up the components of the hour and minute portion - example below:

data _null_;
input hh 2. mm 2.;
time = hms(hh,mm,0);
put time= time5. ;
datalines;
2359
run;


Scott Barry
SBBWorks, Inc.
ChrisNZ
Tourmaline | Level 20
Indeed, Scott's suggestion to let the hms function do the calculation is a bit tidier. You now have:

x='2130';
sastime=input(x,2.)*3600+input(substr(x,3,2),2.)*60;
or
sastime=hms( input(x,2.), input(substr(x,3,2),2.), 0);
or
sastime=input( substr(x,1,2)||':'||substr(x,3,2)||':00', time.);

So many ways with sas! 🙂
Ken_oy
Fluorite | Level 6
But if I have a :

105 (time: 01:05)

how can I do?
Ken_oy
Fluorite | Level 6
well, it will be more easier in excel
change it in excel 105-> 0105
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Forum posting Suggestion: next time create a new post as you being the AUTHOR, and paste a link if needed back to some forum archive reference.

With SAS 9.2, you have the ISO 8601 INFORMAT B8601TM demonstrated below.

Otherwise, you will need to separate the minute- and hour-portion and use the HMS function to derive a SAS numeric TIME variable.

Scott Barry
SBBWorks, Inc.


68 data _null_;
69 c_hmm = '105';
70 n_hmm = input(c_hmm,best.);
71 c_hhmm = put(n_hmm,z6.);
72 n_hmm_sec = input(c_hhmm,b8601tm.);
73 format n_hmm_sec time8.;
74 putlog _all_;
75 run;

c_hmm=105 n_hmm=105 c_hhmm=000105 n_hmm_sec=0:01:05 _ERROR_=0 _N_=1
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds

SAS 9.2 Language Reference, Informats by Category
http://support.sas.com/documentation/cdl/en/lrdict/62618/HTML/default/a001239776.htm Message was edited by: sbb

sas-innovate-2024.png

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.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 6 replies
  • 797 views
  • 0 likes
  • 4 in conversation