<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Any way to check datatype of a variable date or datetime ? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Any-way-to-check-datatype-of-a-variable-date-or-datetime/m-p/12803#M1420</link>
    <description>Hi:&lt;BR /&gt;
  Variables that are SAS date or date/time variables will always be NUMERIC variables....SAS knows that they are meant to be used as DATE or DATE/TIME values by the presence of a format (for display) or an informat (for input). &lt;BR /&gt;
&lt;BR /&gt;
  You might investigate the use of the Dictionary tables or SASHELP files that contain variable information (DICTIONARY.COLUMNS or SASHELP.VCOLUMNS) to determine which variables in which datasets have date or date/time formats/informats assigned.&lt;BR /&gt;
 &lt;BR /&gt;
These papers outline the use of the DICTIONARY and SASHELP files.&lt;BR /&gt;
&lt;A href="http://www2.sas.com/proceedings/sugi29/237-29.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi29/237-29.pdf&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://www2.sas.com/proceedings/sugi31/259-31.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi31/259-31.pdf&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://www2.sas.com/proceedings/sugi30/070-30.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi30/070-30.pdf&lt;/A&gt;&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
    <pubDate>Thu, 29 Apr 2010 17:28:04 GMT</pubDate>
    <dc:creator>Cynthia_sas</dc:creator>
    <dc:date>2010-04-29T17:28:04Z</dc:date>
    <item>
      <title>Any way to check datatype of a variable date or datetime ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Any-way-to-check-datatype-of-a-variable-date-or-datetime/m-p/12802#M1419</link>
      <description>Is there any way to check a variable is holding date value or  datetime value ?&lt;BR /&gt;
There are various date and date time formats can be assigned to a variable. So its difficult to know is the variable having date value or date time value.&lt;BR /&gt;
I am doing some processing in my program depending up on the variable datatype (date or datetime). But variables are having different kinds of formats.&lt;BR /&gt;
&lt;BR /&gt;
Can any body suggest me some idea ?

Message was edited by: anandbillava</description>
      <pubDate>Thu, 29 Apr 2010 16:45:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Any-way-to-check-datatype-of-a-variable-date-or-datetime/m-p/12802#M1419</guid>
      <dc:creator>anandbillava</dc:creator>
      <dc:date>2010-04-29T16:45:50Z</dc:date>
    </item>
    <item>
      <title>Re: Any way to check datatype of a variable date or datetime ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Any-way-to-check-datatype-of-a-variable-date-or-datetime/m-p/12803#M1420</link>
      <description>Hi:&lt;BR /&gt;
  Variables that are SAS date or date/time variables will always be NUMERIC variables....SAS knows that they are meant to be used as DATE or DATE/TIME values by the presence of a format (for display) or an informat (for input). &lt;BR /&gt;
&lt;BR /&gt;
  You might investigate the use of the Dictionary tables or SASHELP files that contain variable information (DICTIONARY.COLUMNS or SASHELP.VCOLUMNS) to determine which variables in which datasets have date or date/time formats/informats assigned.&lt;BR /&gt;
 &lt;BR /&gt;
These papers outline the use of the DICTIONARY and SASHELP files.&lt;BR /&gt;
&lt;A href="http://www2.sas.com/proceedings/sugi29/237-29.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi29/237-29.pdf&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://www2.sas.com/proceedings/sugi31/259-31.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi31/259-31.pdf&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://www2.sas.com/proceedings/sugi30/070-30.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi30/070-30.pdf&lt;/A&gt;&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Thu, 29 Apr 2010 17:28:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Any-way-to-check-datatype-of-a-variable-date-or-datetime/m-p/12803#M1420</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2010-04-29T17:28:04Z</dc:date>
    </item>
    <item>
      <title>Re: Any way to check datatype of a variable date or datetime ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Any-way-to-check-datatype-of-a-variable-date-or-datetime/m-p/12804#M1421</link>
      <description>I am using vcolumns table only. But date and datetime format could be anything. Users can create datasets with different date and datetime formats.&lt;BR /&gt;
If I am not wrong the formats could be any one of the format from below URL&lt;BR /&gt;
&lt;BR /&gt;
&lt;A href="http://www.uc.edu/sashtml/lrcon/zenid-63.htm" target="_blank"&gt;http://www.uc.edu/sashtml/lrcon/zenid-63.htm&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
So Its difficult to know which formats he is using and thus determining the variable datatype date or datetime. Otherwise we have to check for each of the condition from the above URL to determine is it date or datetime..</description>
      <pubDate>Thu, 29 Apr 2010 18:23:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Any-way-to-check-datatype-of-a-variable-date-or-datetime/m-p/12804#M1421</guid>
      <dc:creator>anandbillava</dc:creator>
      <dc:date>2010-04-29T18:23:10Z</dc:date>
    </item>
    <item>
      <title>Re: Any way to check datatype of a variable date or datetime ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Any-way-to-check-datatype-of-a-variable-date-or-datetime/m-p/12805#M1422</link>
      <description>Hi:&lt;BR /&gt;
  Yes, you're right, you would have to check whether a DATE or DATE/TIME format or informat is being used. That URL shows an older list of formats. &lt;BR /&gt;
   &lt;BR /&gt;
The most current list of formats is here:&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/62618/HTML/default/a001263753.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/62618/HTML/default/a001263753.htm&lt;/A&gt;&lt;BR /&gt;
         &lt;BR /&gt;
...and the most current list of informats is here:&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/62618/HTML/default/a001239776.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/62618/HTML/default/a001239776.htm&lt;/A&gt;&lt;BR /&gt;
   &lt;BR /&gt;
If you made a dataset of the possible format and/or informat names, you could do an SQL join or a merge to find whether a column name in DICTIONARY.COLUMNS matched one of the formats or informats in your possible formats dataset.&lt;BR /&gt;
  &lt;BR /&gt;
cynthia</description>
      <pubDate>Thu, 29 Apr 2010 19:36:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Any-way-to-check-datatype-of-a-variable-date-or-datetime/m-p/12805#M1422</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2010-04-29T19:36:07Z</dc:date>
    </item>
    <item>
      <title>Re: Any way to check datatype of a variable date or datetime ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Any-way-to-check-datatype-of-a-variable-date-or-datetime/m-p/12806#M1423</link>
      <description>Hi cynthia,&lt;BR /&gt;
Thanks. But those formats are valid in SAS 9.1.3 ?&lt;BR /&gt;
Because I am still using SAS 9.1.3&lt;BR /&gt;
&lt;BR /&gt;
Anand</description>
      <pubDate>Thu, 29 Apr 2010 19:40:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Any-way-to-check-datatype-of-a-variable-date-or-datetime/m-p/12806#M1423</guid>
      <dc:creator>anandbillava</dc:creator>
      <dc:date>2010-04-29T19:40:53Z</dc:date>
    </item>
    <item>
      <title>Re: Any way to check datatype of a variable date or datetime ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Any-way-to-check-datatype-of-a-variable-date-or-datetime/m-p/12807#M1424</link>
      <description>You can identify the format being used by running proc contents to a data table and examining the format column.&lt;BR /&gt;
&lt;BR /&gt;
proc contents data=filename noprint out=table_contents;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Another way is to examine the unformatted values. Dates will be 5 digits. Datetimes will be 10 or 11 digits.</description>
      <pubDate>Thu, 29 Apr 2010 19:50:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Any-way-to-check-datatype-of-a-variable-date-or-datetime/m-p/12807#M1424</guid>
      <dc:creator>barheat</dc:creator>
      <dc:date>2010-04-29T19:50:57Z</dc:date>
    </item>
    <item>
      <title>Re: Any way to check datatype of a variable date or datetime ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Any-way-to-check-datatype-of-a-variable-date-or-datetime/m-p/12808#M1425</link>
      <description>I know about that. &lt;BR /&gt;
But my question to cynthia was the URL he mentioned with new formats are for version 9.1.3 or 9.2 ?</description>
      <pubDate>Thu, 29 Apr 2010 20:13:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Any-way-to-check-datatype-of-a-variable-date-or-datetime/m-p/12808#M1425</guid>
      <dc:creator>anandbillava</dc:creator>
      <dc:date>2010-04-29T20:13:24Z</dc:date>
    </item>
    <item>
      <title>Re: Any way to check datatype of a variable date or datetime ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Any-way-to-check-datatype-of-a-variable-date-or-datetime/m-p/12809#M1426</link>
      <description>Hi:&lt;BR /&gt;
  That original URL with the list of formats looked to me like the old Version 8 form of the documentation. Since it wasn't a support.sas.com URL, it is hard to say. However, &lt;BR /&gt;
 &lt;BR /&gt;
  If you need to check the 9.1.3 documentation, then the 9.1.3 list of formats is here:&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/onlinedoc/91pdf/sasdoc_913/base_lrdictionary_10307.pdf" target="_blank"&gt;http://support.sas.com/documentation/onlinedoc/91pdf/sasdoc_913/base_lrdictionary_10307.pdf&lt;/A&gt; (page 84) or &lt;BR /&gt;
&lt;A href="http://support.sas.com/onlinedoc/913/getDoc/en/lrdict.hlp/a001263753.htm" target="_blank"&gt;http://support.sas.com/onlinedoc/913/getDoc/en/lrdict.hlp/a001263753.htm&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
  The documentation links that I previously posted were from the 9.2 documentation. However, there would be no harm (except a fractional amount of processing) in using the 9.2 list -- because then you would not have to revise the program again for SAS 9.2.&lt;BR /&gt;
&lt;BR /&gt;
cynthia</description>
      <pubDate>Thu, 29 Apr 2010 22:07:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Any-way-to-check-datatype-of-a-variable-date-or-datetime/m-p/12809#M1426</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2010-04-29T22:07:08Z</dc:date>
    </item>
    <item>
      <title>Re: Any way to check datatype of a variable date or datetime ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Any-way-to-check-datatype-of-a-variable-date-or-datetime/m-p/12810#M1427</link>
      <description>See you are saying the one you posted in the first URL can work for both the version. or Do i need join both the information ?</description>
      <pubDate>Fri, 30 Apr 2010 00:05:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Any-way-to-check-datatype-of-a-variable-date-or-datetime/m-p/12810#M1427</guid>
      <dc:creator>anandbillava</dc:creator>
      <dc:date>2010-04-30T00:05:38Z</dc:date>
    </item>
    <item>
      <title>Re: Any way to check datatype of a variable date or datetime ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Any-way-to-check-datatype-of-a-variable-date-or-datetime/m-p/12811#M1428</link>
      <description>Consider using a "reasonable value" check which would involve using a "date" or "datetime" range generated using the INTNX function and you decide what might be a reasonable range to test -- if the value is outside the range then it must not be the type you are testing for.  Of course you could also test the equivalent "datetime" range as well.  I agree that using a test for particular output formats is problematic, when date-related SAS output formats are numerous.  Better to check for "a value within a declared range using INTNX".&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Fri, 30 Apr 2010 02:05:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Any-way-to-check-datatype-of-a-variable-date-or-datetime/m-p/12811#M1428</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-04-30T02:05:20Z</dc:date>
    </item>
    <item>
      <title>Re: Any way to check datatype of a variable date or datetime ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Any-way-to-check-datatype-of-a-variable-date-or-datetime/m-p/12812#M1429</link>
      <description>If you decide to use the associated format to determine SAS Date/Time related variables it might be easier to let your data help you build the lookup table.   You can add to it with each new library.  The code below looks at a library and builds a list of unique format names.  From this you can make an INFORMAT that would incode a format name as you desire.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
proc contents noprint &lt;BR /&gt;
      out=fmts(keep=format where=(not missing(format))) &lt;BR /&gt;
      data=sashelp._all_;&lt;BR /&gt;
   run;&lt;BR /&gt;
proc sort data=fmts nodupkey;&lt;BR /&gt;
   by format;&lt;BR /&gt;
   run;&lt;BR /&gt;
proc print;&lt;BR /&gt;
   run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Using the output from PROC CONTENTS create an INFORMAT...&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data control;&lt;BR /&gt;
   retain fmtname 'ftyp' type 'J' hlo 'UJ ';&lt;BR /&gt;
   infile cards eof=eof;&lt;BR /&gt;
   input label:$2. start:$32.;&lt;BR /&gt;
   output;&lt;BR /&gt;
   return;&lt;BR /&gt;
 eof:&lt;BR /&gt;
   call missing(start);&lt;BR /&gt;
   label = '?';&lt;BR /&gt;
   hlo   = cats(hlo,'O');&lt;BR /&gt;
   output;&lt;BR /&gt;
   cards;&lt;BR /&gt;
 C  $&lt;BR /&gt;
 C  $CHAR&lt;BR /&gt;
 C  $HEX&lt;BR /&gt;
 N  BEST&lt;BR /&gt;
 N  COMMA&lt;BR /&gt;
 D  DATE&lt;BR /&gt;
 DT DATETIME&lt;BR /&gt;
 N  DOLLAR&lt;BR /&gt;
 N  HEX&lt;BR /&gt;
 D  MONNAME&lt;BR /&gt;
 D  MONYY&lt;BR /&gt;
 T  TIME&lt;BR /&gt;
 D  WEEKDATX&lt;BR /&gt;
 D  YEAR&lt;BR /&gt;
 D  YYQ&lt;BR /&gt;
 D  YYQC&lt;BR /&gt;
 N  Z&lt;BR /&gt;
;;;;&lt;BR /&gt;
   run;&lt;BR /&gt;
proc format cntlin=control;&lt;BR /&gt;
   select @$ftyp;&lt;BR /&gt;
   run;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Fri, 30 Apr 2010 11:57:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Any-way-to-check-datatype-of-a-variable-date-or-datetime/m-p/12812#M1429</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2010-04-30T11:57:32Z</dc:date>
    </item>
    <item>
      <title>Re: Any way to check datatype of a variable date or datetime ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Any-way-to-check-datatype-of-a-variable-date-or-datetime/m-p/12813#M1430</link>
      <description>Yes, the 9.2 documentation for formats and informations should contain all the 9.1.3 formats and informats PLUS any new formats and informats that were added for 9.2. Generally, formats and informats are ADDED in new releases. I am not aware of any formats or informats that have been removed.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Fri, 30 Apr 2010 15:52:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Any-way-to-check-datatype-of-a-variable-date-or-datetime/m-p/12813#M1430</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2010-04-30T15:52:21Z</dc:date>
    </item>
    <item>
      <title>Re: Any way to check datatype of a variable date or datetime ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Any-way-to-check-datatype-of-a-variable-date-or-datetime/m-p/12814#M1431</link>
      <description>But the problem here is user can have format defined as ddmmyy10. Here the 10 number is always floating. So there is goin to be lot of formats with this.</description>
      <pubDate>Sun, 02 May 2010 13:28:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Any-way-to-check-datatype-of-a-variable-date-or-datetime/m-p/12814#M1431</guid>
      <dc:creator>anandbillava</dc:creator>
      <dc:date>2010-05-02T13:28:20Z</dc:date>
    </item>
    <item>
      <title>Re: Any way to check datatype of a variable date or datetime ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Any-way-to-check-datatype-of-a-variable-date-or-datetime/m-p/12815#M1432</link>
      <description>anandbillava &lt;BR /&gt;
&lt;BR /&gt;
since the possible list of date and datetime formats is very long &lt;BR /&gt;
(consider that there are many NLS formats for each of the basic date and time formats, and that a user table could use a date format that is user-defined with proc format, I do not think providing a specific list will be a 100% solution), &lt;BR /&gt;
but, perhaps you do not seek a 100% solution.&lt;BR /&gt;
If so read on:[pre]1    %put %sysfunc( putn("31dec3000"d     , best12 )) ;&lt;BR /&gt;
380217&lt;BR /&gt;
2    %put %sysfunc( putn("31dec1990:0:0"dt, best12 )) ;&lt;BR /&gt;
978220800[/pre] indicates that the largest date I imagine you need to consider(31Dec3000 ?) and the earliest timestamp (beginning of 1990?)  are so far apart, you can use the value range to indicate what the value holds.... whether date (value &amp;lt; 380217) or timestamp (value &amp;gt; 400000)&lt;BR /&gt;
In fact a value 400000 refers to a timestamp at the beginning of the 1960's &amp;gt;&amp;gt;&amp;gt;&amp;gt; [pre]3    %put %sysfunc( putn( 400000, datetime. ));&lt;BR /&gt;
05JAN60:15:06:40&lt;BR /&gt;
4    %put %sysfunc( putn( 400000, date11. ));&lt;BR /&gt;
01-MAR-3055[/pre] and a date in year 3055. I guess that provides enough separation for most data management needs.&lt;BR /&gt;
 &lt;BR /&gt;
unless you have more to explain  ...?&lt;BR /&gt;
 &lt;BR /&gt;
hoping to hear that this is the way you are happy "&lt;B&gt;to check datatype of a variable date or datetime&lt;/B&gt;" &lt;BR /&gt;
or that you mave more specific requirements&lt;BR /&gt;
 &lt;BR /&gt;
PeterC</description>
      <pubDate>Sun, 02 May 2010 16:11:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Any-way-to-check-datatype-of-a-variable-date-or-datetime/m-p/12815#M1432</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2010-05-02T16:11:33Z</dc:date>
    </item>
    <item>
      <title>Re: Any way to check datatype of a variable date or datetime ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Any-way-to-check-datatype-of-a-variable-date-or-datetime/m-p/12816#M1433</link>
      <description>I guess I'm confused by your description of what you want. At first, I thought you wanted to search through a library and find out whether there were any date variables based on looking up the variable format compared to a list. But then some other folks interpreted your question as wanting to know whether the variable VALUES were valid date or date/time values. However, I'm going to stick with my original interpretation...and guess that this most recent question has to do with the fact that the documentation lists just the "base" name of the format (or informat) and doesn't show a width, while in actual usage, the format width can vary.&lt;BR /&gt;
 &lt;BR /&gt;
For example, as you note, a variable could be defined for actual usage with a format of DDMMYY10 or DDMMYY8 or MMDDYY10 or MMDDYY6 or MMDDYY8. So yes, the WIDTH of the formatted field could always be different in the dataset descriptor. However, the basic format name for the above 2 examples is either DDMMYY or MMDDYY....without regard to the WIDTH of the formatted value. You can easily read the FORMAT variable out of DICTIONARY.COLUMNS and extract only the character portion of the format name using the SCAN function. Something like this:&lt;BR /&gt;
[pre]&lt;BR /&gt;
  method1 = scan(fmtval,1,'1234567890.');&lt;BR /&gt;
  method2 = scan(fmtval,1,,'dp');&lt;BR /&gt;
[/pre]&lt;BR /&gt;
   &lt;BR /&gt;
The first scan method statement just hard-codes digits and a period as the delimiters for the SCAN function. The second method uses the 'dp' modifiers to the SCAN function instead of typing the list of numbers and punctuation. In either case, the result of using both methods would be that MMDDYY8. and MMDDYY10. as format values would become MMDDYY ... In the program below, I use the first method to compare formats from DICTIONARY.COLUMNS against a small checklist dataset of format names. Partial output from the program is shown after the program.&lt;BR /&gt;
 &lt;BR /&gt;
With this report in hand, you could either code a macro program or code a series of PROC FREQ, PROC MEANS or PROC UNIVARIATE steps to test the values in these particular variables to see what the range of date or date/time values was and whether they were reasonable values for the processing you need to do.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia&lt;BR /&gt;
[pre]&lt;BR /&gt;
data checklist;&lt;BR /&gt;
  infile datalines;&lt;BR /&gt;
  input fwant $;&lt;BR /&gt;
  select_match = 'FORMAT';&lt;BR /&gt;
  fwant = upcase(fwant);&lt;BR /&gt;
return;&lt;BR /&gt;
datalines;&lt;BR /&gt;
date&lt;BR /&gt;
mmddyy&lt;BR /&gt;
monname&lt;BR /&gt;
weekdate&lt;BR /&gt;
datetime&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
                         &lt;BR /&gt;
ods listing;&lt;BR /&gt;
options linesize=150;&lt;BR /&gt;
                         &lt;BR /&gt;
proc sql;&lt;BR /&gt;
  create table datevars as&lt;BR /&gt;
  select b.select_match, a.libname, a.memname, a.name, a.type, &lt;BR /&gt;
         a.informat, a.format, &lt;BR /&gt;
         scan(a.format,1,'1234567890.') as f_name,&lt;BR /&gt;
         a.length, a.label&lt;BR /&gt;
  from dictionary.columns as a,&lt;BR /&gt;
       work.checklist as b&lt;BR /&gt;
  where (calculated f_name = b.fwant) &lt;BR /&gt;
  order by a.libname, a.memname, a.name;&lt;BR /&gt;
quit;&lt;BR /&gt;
                     &lt;BR /&gt;
proc print data=work.datevars;&lt;BR /&gt;
  title 'Date variables in DICTIONARY.COLUMNS with date format';&lt;BR /&gt;
run;&lt;BR /&gt;
             &lt;BR /&gt;
[/pre]&lt;BR /&gt;
                               &lt;BR /&gt;
Partial output:&lt;BR /&gt;
[pre]&lt;BR /&gt;
       select_&lt;BR /&gt;
Obs     match     libname    memname     name        type    informat       format         f_name      length    label&lt;BR /&gt;
&lt;BR /&gt;
  1    FORMAT     MAPS       NCC         DATE        num                    DATETIME20.    DATETIME       8&lt;BR /&gt;
  2    FORMAT     MAPS       NCD         DATE        num                    DATETIME20.    DATETIME       8&lt;BR /&gt;
  3    FORMAT     MAPS       NCN         DATE        num                    DATETIME20.    DATETIME       8&lt;BR /&gt;
  4    FORMAT     MAPS       USAC        DATE        num                    DATETIME20.    DATETIME       8&lt;BR /&gt;
  5    FORMAT     MAPS       USAD        DATE        num                    DATETIME20.    DATETIME       8&lt;BR /&gt;
  6    FORMAT     MAPS       USAN        DATE        num                    DATETIME20.    DATETIME       8&lt;BR /&gt;
  7    FORMAT     MAPS       WAKEC       DATE        num                    DATETIME20.    DATETIME       8&lt;BR /&gt;
  8    FORMAT     MAPS       WAKED       DATE        num                    DATETIME20.    DATETIME       8&lt;BR /&gt;
  9    FORMAT     MAPS       WAKEN       DATE        num                    DATETIME20.    DATETIME       8&lt;BR /&gt;
 10    FORMAT     SASHELP    ASSOCWA     _LOADTM     num     DATETIME20.    DATETIME20.    DATETIME       8      DateTime Stamp of when row was loaded&lt;BR /&gt;
 11    FORMAT     SASHELP    BUY         DATE        num                    DATE9.         DATE           8      Date&lt;BR /&gt;
 12    FORMAT     SASHELP    CITIDAY     DATE        num                    DATE9.         DATE           7      Date of Observation&lt;BR /&gt;
 13    FORMAT     SASHELP    GNGSMP2     Date        num                    DATE.          DATE           8&lt;BR /&gt;
 14    FORMAT     SASHELP    GNGSMP2     DateTime    num                    DATETIME14.    DATETIME       8&lt;BR /&gt;
 15    FORMAT     SASHELP    MDV         SHIPDATE    num     DATE.          DATE7.         DATE           8&lt;BR /&gt;
 16    FORMAT     SASHELP    NVST1       DATE        num                    DATE9.         DATE           8      Date&lt;BR /&gt;
 17    FORMAT     SASHELP    NVST2       DATE        num                    DATE9.         DATE           8      Date&lt;BR /&gt;
 18    FORMAT     SASHELP    NVST3       DATE        num                    DATE9.         DATE           8      Date&lt;BR /&gt;
 19    FORMAT     SASHELP    NVST4       DATE        num                    DATE9.         DATE           8      Date&lt;BR /&gt;
 20    FORMAT     SASHELP    NVST5       DATE        num                    DATE9.         DATE           8      Date&lt;BR /&gt;
 21    FORMAT     SASHELP    PRDSAL2     MONTH       num                    MONNAME3.      MONNAME        8      Month&lt;BR /&gt;
 22    FORMAT     SASHELP    PRDSAL3     MONTH       num                    MONNAME3.      MONNAME        8      Month&lt;BR /&gt;
 23    FORMAT     SASHELP    PRDSALE     MONTH       num                    MONNAME3.      MONNAME        8      Month&lt;BR /&gt;
   &lt;BR /&gt;
[/pre]</description>
      <pubDate>Sun, 02 May 2010 18:06:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Any-way-to-check-datatype-of-a-variable-date-or-datetime/m-p/12816#M1433</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2010-05-02T18:06:40Z</dc:date>
    </item>
    <item>
      <title>Re: Any way to check datatype of a variable date or datetime ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Any-way-to-check-datatype-of-a-variable-date-or-datetime/m-p/12817#M1434</link>
      <description>Another (quick and dirty) way is to test actual values.&lt;BR /&gt;
&lt;BR /&gt;
3 millions gives you a date past year 9999, but a date time in feb 1960.&lt;BR /&gt;
&lt;BR /&gt;
so unless you deal with dates going back to 1960, you can be safe assuming that &lt;BR /&gt;
&lt;BR /&gt;
value &amp;gt; 3e6 means datetime&lt;BR /&gt;
&lt;BR /&gt;
value &amp;lt; 3e6 means date.&lt;BR /&gt;
&lt;BR /&gt;
If you might use 1960 or older dates, you need to use formats as seen above.</description>
      <pubDate>Mon, 03 May 2010 01:59:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Any-way-to-check-datatype-of-a-variable-date-or-datetime/m-p/12817#M1434</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2010-05-03T01:59:50Z</dc:date>
    </item>
    <item>
      <title>Re: Any way to check datatype of a variable date or datetime ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Any-way-to-check-datatype-of-a-variable-date-or-datetime/m-p/12818#M1435</link>
      <description>Thanks cynthia. I used compress method instead of scan function. &lt;BR /&gt;
I have completed my program on this. Its working fine now.</description>
      <pubDate>Mon, 03 May 2010 14:45:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Any-way-to-check-datatype-of-a-variable-date-or-datetime/m-p/12818#M1435</guid>
      <dc:creator>anandbillava</dc:creator>
      <dc:date>2010-05-03T14:45:22Z</dc:date>
    </item>
    <item>
      <title>Re: Any way to check datatype of a variable date or datetime ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Any-way-to-check-datatype-of-a-variable-date-or-datetime/m-p/12819#M1436</link>
      <description>The problem you have is that SAS only has two data types: Character and Numeric.  SAS stores dates and times as numeric data type and the fact that the value stored is a date or date time is lost unless you document that somewhere.&lt;BR /&gt;
Assigning a format or informat is one way to document it (internally within the dataset itself)  but that is prone to problems, because anyone who has write access to your dataset can change the format or informat attribute.  Not ony that someone might just rename your variable and remove the format and informat.  &lt;BR /&gt;
The dictionary tables can be used to extract a lot of attibute information that can then be used programatically.  If you do know the date and datetime ranges reliably (ie the data was entered under some programatic control over the values entered and not just entered as free text) then you can do some basic range testing.  you could also use a number of SAS functions for extracting parts of the date or date time, and see if they conformed to the valid range of values.&lt;BR /&gt;
You can also use the put function to write a value in a specified date or date time format as text, assign the value to a character variable and then use character manipulation functions to pull off parts of the text and compare agains a list of month names for example.&lt;BR /&gt;
&lt;BR /&gt;
If you have no knowledge or certainty about the source of the data, and that the values of a particular variable are dates or date times, then you expose yourself to some risk in making that assumption.  The risk will depend on the consequences of the error.</description>
      <pubDate>Wed, 05 May 2010 03:15:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Any-way-to-check-datatype-of-a-variable-date-or-datetime/m-p/12819#M1436</guid>
      <dc:creator>monei011</dc:creator>
      <dc:date>2010-05-05T03:15:32Z</dc:date>
    </item>
  </channel>
</rss>

