Help using Base SAS procedures

Timevar format issue

Reply
N/A
Posts: 0

Timevar format issue

This is the timevar as it currently reads: 2009-03-24T09:00 it is considered character format $200.

by a simple recoding I can get: 200903240900 Best12. format

I would like to have this in timedate format or be able to split it into the time and date seperately.

(the dataset was imported from a seperate comapny I did not create it)

Any help or insight would be wonderful! Smiley Happy
SAS Super FREQ
Posts: 8,744

Re: Timevar format issue

Hi,
To convert a character string to a numeric variable you would use an assignment statement, something like:
[pre]
numvar = input(charvar,informat_name.);
[/pre]

if your character string is in a date or date time form, then you would need to look up the correct INformat in the documentation. BEST12 would NOT be the correct INformat to use.

Cynthia
Super Contributor
Super Contributor
Posts: 3,174

Re: Timevar format issue

Recommended Google advanced search argument for this topic/post:

sas datetime values site:sas.com

Also, there are SAS functions DATEPART and TIMEPART, if you want to split a DATETIME variable. And, as Cynthia mentioned, it's key to apply the proper SAS format as you desire the output to be displayed, since SAS DATE and DATETIME variables are numeric internally, as can be picked-up from the DOC references.

Scott Barry
SBBWorks, Inc.
Valued Guide
Posts: 2,175

Re: Timevar format issue

there are informats like IS8601xx (in SAS9) which I think are designed to handle these types of date and time data formats.
There is also ANYDTDTM informat which would search for a suitable datetime informat. It gave me these results (SAS9.1.3 sp4)
436 %put %sysfunc( inputn( %str(2009-03-24T09:00), anydtdtm), datetime );
.
437 %put %sysfunc( inputn( %str(2009-03-24T09:00:00), anydtdtm), datetime );
24MAR09:09:00:00

This shows that the informat ANYDTDTM expects the seconds to be provided.
So does IS8601DT.
Ask a Question
Discussion stats
  • 3 replies
  • 128 views
  • 0 likes
  • 4 in conversation