formats and informats

Accepted Solution Solved
Reply
Contributor
Posts: 45
Accepted Solution

formats and informats

I'm trying to get this line of code to work

WHERE Acty_Tmstmp BETWEEN E_Dt AND C_Dt

The problem is that ACTY_TMSTMP is in char $26.

E_Dt and C_Dt are both in num DATE9.

From reading other strings, i know i need to do something with the input command and changing the informat, but I don't have a clue. Only 5 months into using SAS.

I'm not asking to see these fields (so not in my select section).

Thanks for your help!

See my code so far...

Attachment

Accepted Solutions
Solution
‎10-18-2013 03:51 PM
Super User
Super User
Posts: 7,039

Re: formats and informats

Posted in reply to SVoldrich

You can use the INPUT() function to apply an informat to the value stored in a character variable.  If the value is consistently in a particular format then use the appropriate informat.  Otherwise try using the ANYDTDTE. informat.

WHERE input(acty_Tmstmp,anydtdte.) BETWEEN E_Dt AND C_Dt ;

View solution in original post


All Replies
Solution
‎10-18-2013 03:51 PM
Super User
Super User
Posts: 7,039

Re: formats and informats

Posted in reply to SVoldrich

You can use the INPUT() function to apply an informat to the value stored in a character variable.  If the value is consistently in a particular format then use the appropriate informat.  Otherwise try using the ANYDTDTE. informat.

WHERE input(acty_Tmstmp,anydtdte.) BETWEEN E_Dt AND C_Dt ;

Contributor
Posts: 45

Re: formats and informats

Thanks Tom! That really helped.

I am still learning the different formats and I think that is what is so tricky for me.

The Acty_Tmstp is actually in a format of 2013-10-21 11:12:30.5 format. date and time - but is listed as character.

I suppose to query only those that happened since 1/1/13, I will need to make this more of a date format, otherwise I will have to find out what number is the equivelent of 1/1/13. Right?

Super Contributor
Posts: 339

Re: formats and informats

Posted in reply to SVoldrich

You can either use

input("01/01/2013", ddmmyy10.); to calculate the numeric value of 1/1/13. You can also use the date9. shortened input syntax as "01JAN2013"d. The d following the date string in a date9 format turns it into it's numeric representation value directly.

It is possible to input anydtdtm for "any datetime" instead of anydtdte if you wish to extract the full datetime but since you only care for a particular date and not a datetime as a cutoff, anydtdte should naturally extract 2013-10-21 from your datetime string.

If the string always has the same format, you can also consider something like

input(substr(acty_tmstp, 1, 10), yymmdd10.) to also extract the date directly

Super User
Super User
Posts: 7,039

Re: formats and informats

Posted in reply to SVoldrich

You do not need to know the number as you can use date literals in your code.

where input(acty_Tmstmp,anydtdte.) > '01JAN2013'd ;


Since your character variable is actually datatime instead of date you need check how your other date variables are coded. SAS will store dates as number of days and datetime as number of seconds.  You can also use datetime literals

where input(acty_Tmstmp,anydtdtm.) > '01JAN2013:00:00'dt ;


🔒 This topic is solved and locked.

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

Discussion stats
  • 4 replies
  • 334 views
  • 3 likes
  • 3 in conversation