Hi,I Need some guidance !(datetime format,need to read this:Tuesday, April 17, 2012 14:29:48 UTC )

Accepted Solution Solved
Reply
Contributor
Posts: 21
Accepted Solution

Hi,I Need some guidance !(datetime format,need to read this:Tuesday, April 17, 2012 14:29:48 UTC )

Hello All,

I am trying to import a css file and it has some earthquake data.

The variables are:

Src,EqId,Version,Datetime,Lat,Lon,Magnitude,Depth,NST,Region

Now under the Datetime column,the observation is in the following format-

"Tuesday, April 17, 2012 14:29:48 UTC"

Kindly help me here on how to read this value.

Thanks and Regards.

Shaheen Ranalvi

Attachment

Accepted Solutions
Solution
‎04-18-2012 09:36 AM
Super User
Super User
Posts: 6,502

Re: Hi,I Need some guidance !

I don't think SAS can read that format directly.  Read it as a character variable and then parse out the pieces and rearrange them into an order that SAS can read.  All of your examples have UTC at the end, so you might be able to just ignore that part, as the times will be consistent relative to each other.  If you need to get them into your local time then add or subtract the right number of hours from UTC.

data test;

  length Src $5 EqId $12 Version $1 DatetimeC $50 Lat Lon Magnitude Depth 8 NST $1 Region $60 ;

  infile tmpfile1 dsd truncover firstobs=2;

  input @;

  _infile_ = translate(_infile_,'.','?');

  input src -- region;

  datetime  = input(

    scan(datetimec,3,', ')||substr(scan(datetimec,2,', '),1,3)

  ||scan(datetimec,4,', ')||':'||scan(datetimec,5,', '),datetime.);

  format datetime datetime.;

  put (datetimeSmiley Happy (=) ;

run;


DatetimeC=Wednesday, April 18, 2012 01:15:15 UTC datetime=18APR12:01:15:15

DatetimeC=Tuesday, April 17, 2012 19:45:36 UTC datetime=17APR12:19:45:36

View solution in original post


All Replies
Solution
‎04-18-2012 09:36 AM
Super User
Super User
Posts: 6,502

Re: Hi,I Need some guidance !

I don't think SAS can read that format directly.  Read it as a character variable and then parse out the pieces and rearrange them into an order that SAS can read.  All of your examples have UTC at the end, so you might be able to just ignore that part, as the times will be consistent relative to each other.  If you need to get them into your local time then add or subtract the right number of hours from UTC.

data test;

  length Src $5 EqId $12 Version $1 DatetimeC $50 Lat Lon Magnitude Depth 8 NST $1 Region $60 ;

  infile tmpfile1 dsd truncover firstobs=2;

  input @;

  _infile_ = translate(_infile_,'.','?');

  input src -- region;

  datetime  = input(

    scan(datetimec,3,', ')||substr(scan(datetimec,2,', '),1,3)

  ||scan(datetimec,4,', ')||':'||scan(datetimec,5,', '),datetime.);

  format datetime datetime.;

  put (datetimeSmiley Happy (=) ;

run;


DatetimeC=Wednesday, April 18, 2012 01:15:15 UTC datetime=18APR12:01:15:15

DatetimeC=Tuesday, April 17, 2012 19:45:36 UTC datetime=17APR12:19:45:36

Contributor
Posts: 21

Re: Hi,I Need some guidance !

Thanks Tom.It worked beautifully..perfect solution.Smiley Happy

Regards,

Shaheen ranalvi

Occasional Contributor
Posts: 15

Re: Hi,I Need some guidance !

Please use next time a precise title! Smiley Happy

Regards,

Raphael

Contributor
Posts: 21

Re: Hi,I Need some guidance !

Thank you for the correction,i've updated the heading.

New to this forum that is why this mistake!!

Thanks a tonne and Regards,

Shaheen Ranalvi

☑ This topic is solved.

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

Discussion stats
  • 4 replies
  • 1143 views
  • 2 likes
  • 3 in conversation