<?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: Issue with trying to clean a variable with different date layouts in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Issue-with-trying-to-clean-a-variable-with-different-date/m-p/17209#M3246</link>
    <description>Your post is somewhat confusing, mostly with attempts to describe the data-content to be converted.  May I suggest you simply list the data-column lines with no interpretation, to start?&lt;BR /&gt;
&lt;BR /&gt;
What you will want to do is use a SAS DATA step, read up your data line as text into a SAS character variable, attempt to interrogate the data-format with code:&lt;BR /&gt;
&lt;BR /&gt;
IF &lt;CONDITION&gt; THEN &lt;ASSIGNMENT_CODE&gt; ;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
The SAS INPUT function will be your friend -- used to convert the character-format data to a SAS DATE variable.  Then, if you need to have separate SAS variables (columns) with the YEAR, MONTH and DAY represented as integer values, you will want to use the YEAR, MONTH and DAY function.&lt;BR /&gt;
&lt;BR /&gt;
Suggest you start by reading SAS documentation on this topic - some references I found at the SAS support  &lt;A href="http://support.sas.com/" target="_blank"&gt;http://support.sas.com/&lt;/A&gt;  website (using the SEARCH facility) are listed below:&lt;BR /&gt;
&lt;BR /&gt;
Working with Dates in the SAS System&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/a001304321.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/a001304321.htm&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
SAS Language Dictionary - Informats by Category&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/61724/HTML/default/a001239776.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/61724/HTML/default/a001239776.htm&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
SAS Dates, Times, and Interval Functions&lt;BR /&gt;
&lt;A href="http://support.sas.com/techsup/technote/ts668.pdf" target="_blank"&gt;http://support.sas.com/techsup/technote/ts668.pdf&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;/ASSIGNMENT_CODE&gt;&lt;/CONDITION&gt;</description>
    <pubDate>Fri, 10 Apr 2009 12:11:44 GMT</pubDate>
    <dc:creator>sbb</dc:creator>
    <dc:date>2009-04-10T12:11:44Z</dc:date>
    <item>
      <title>Issue with trying to clean a variable with different date layouts</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Issue-with-trying-to-clean-a-variable-with-different-date/m-p/17208#M3245</link>
      <description>I have a column that is Text and I need to break up the dates in seperate Month, Day, Year columns.  My only problem is that the data looks like this&lt;BR /&gt;
&lt;BR /&gt;
5/        -Month column = 5 and Day and Year will be 99&lt;BR /&gt;
11/      -Month column = 11 and Day and Year will be 99&lt;BR /&gt;
1992   -Year column = 1992 and Month and Day will be 99&lt;BR /&gt;
Nov-64 -Month column = 11 and Year column = 1964 and Day will be 99.&lt;BR /&gt;
&lt;BR /&gt;
99 is just a default value&lt;BR /&gt;
&lt;BR /&gt;
How can I break up each of those into the correct columns?&lt;BR /&gt;
&lt;BR /&gt;
Thank You</description>
      <pubDate>Thu, 09 Apr 2009 19:43:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Issue-with-trying-to-clean-a-variable-with-different-date/m-p/17208#M3245</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-04-09T19:43:04Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with trying to clean a variable with different date layouts</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Issue-with-trying-to-clean-a-variable-with-different-date/m-p/17209#M3246</link>
      <description>Your post is somewhat confusing, mostly with attempts to describe the data-content to be converted.  May I suggest you simply list the data-column lines with no interpretation, to start?&lt;BR /&gt;
&lt;BR /&gt;
What you will want to do is use a SAS DATA step, read up your data line as text into a SAS character variable, attempt to interrogate the data-format with code:&lt;BR /&gt;
&lt;BR /&gt;
IF &lt;CONDITION&gt; THEN &lt;ASSIGNMENT_CODE&gt; ;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
The SAS INPUT function will be your friend -- used to convert the character-format data to a SAS DATE variable.  Then, if you need to have separate SAS variables (columns) with the YEAR, MONTH and DAY represented as integer values, you will want to use the YEAR, MONTH and DAY function.&lt;BR /&gt;
&lt;BR /&gt;
Suggest you start by reading SAS documentation on this topic - some references I found at the SAS support  &lt;A href="http://support.sas.com/" target="_blank"&gt;http://support.sas.com/&lt;/A&gt;  website (using the SEARCH facility) are listed below:&lt;BR /&gt;
&lt;BR /&gt;
Working with Dates in the SAS System&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/a001304321.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/a001304321.htm&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
SAS Language Dictionary - Informats by Category&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/61724/HTML/default/a001239776.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/61724/HTML/default/a001239776.htm&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
SAS Dates, Times, and Interval Functions&lt;BR /&gt;
&lt;A href="http://support.sas.com/techsup/technote/ts668.pdf" target="_blank"&gt;http://support.sas.com/techsup/technote/ts668.pdf&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;/ASSIGNMENT_CODE&gt;&lt;/CONDITION&gt;</description>
      <pubDate>Fri, 10 Apr 2009 12:11:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Issue-with-trying-to-clean-a-variable-with-different-date/m-p/17209#M3246</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-04-10T12:11:44Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with trying to clean a variable with different date layouts</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Issue-with-trying-to-clean-a-variable-with-different-date/m-p/17210#M3247</link>
      <description>Scott,&lt;BR /&gt;
Thank you for the reply and sorry about the confusion.&lt;BR /&gt;
&lt;BR /&gt;
This is a sample of data from 1 column in my data table.&lt;BR /&gt;
BirthDate&lt;BR /&gt;
5/ &lt;BR /&gt;
11/&lt;BR /&gt;
1992 &lt;BR /&gt;
Nov-64 &lt;BR /&gt;
&lt;BR /&gt;
What I did was exactly what you suggested.  I created a data step with the length of each rows data.  Then I created another data step that had if conditions that checked if length is 1 do this and if it's 2 do this and so on.  I was trying to do it in clearner way but I don't think I have any choice but to address each varition.  &lt;BR /&gt;
&lt;BR /&gt;
Thank You &lt;BR /&gt;
Jerry</description>
      <pubDate>Fri, 10 Apr 2009 12:37:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Issue-with-trying-to-clean-a-variable-with-different-date/m-p/17210#M3247</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-04-10T12:37:38Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with trying to clean a variable with different date layouts</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Issue-with-trying-to-clean-a-variable-with-different-date/m-p/17211#M3248</link>
      <description>You might find the MDY function beneficial when working with valid integers (converted from your text string using INPUT and the appropriate INFORMAT).  And if you want to derive a DATETIME variable (for extra-credit), use a combination of DHMS and inside it MDY to get SAS to yield a numeric (internal) value representing "seconds since 1/1/1960".&lt;BR /&gt;
&lt;BR /&gt;
Keep in mind that you can concatenate literal strings with your "variable" input data record fields or sub-fields (using either the SCAN or INDEX / FIND functions) when parsing your data.  For example if you have a data-condition where only a year value is known, you may have an assignment statement (note that there is one year-value string with an imbedded alpha O character):&lt;BR /&gt;
&lt;BR /&gt;
DATA _NULL_;&lt;BR /&gt;
LENGTH DATESTRING $50;  /* ARBITRARY LENGTH */&lt;BR /&gt;
INPUT DATESTRING $;&lt;BR /&gt;
FORMAT MYDATE YYMMDD10. ;  /* YOU DECIDE OUTPUT FMT */&lt;BR /&gt;
* LOGIC HERE TO TEST FOR YEAR PORTION ONLY ;&lt;BR /&gt;
IF LENGTH(DATESTRING) IN (2,4) AND ANYALPHA(DATESTRING) = 0 THEN&lt;BR /&gt;
   MYDATE = INPUT("1/1/" !! DATESTRING,ANYDTDTE.);&lt;BR /&gt;
/*  ELSE IF &lt;MORE logic="" goes="" here=""&gt;  THEN &lt;ASSIGNMENT&gt; ; */ ;&lt;BR /&gt;
IF MYDATE NE . THEN PUTLOG "&amp;gt;INFO&amp;gt; TRANSLATED OKAY: " MYDATE=;&lt;BR /&gt;
ELSE PUTLOG "&amp;gt;ERROR&amp;gt; TRANSLATED BAD - INPUT DATA FOLLOWS: " / &lt;BR /&gt;
        _INFILE_ / &lt;BR /&gt;
        "&amp;gt;ERROR&amp;gt;";&lt;BR /&gt;
DATALINES;&lt;BR /&gt;
1992&lt;BR /&gt;
92&lt;BR /&gt;
2019&lt;BR /&gt;
2O01&lt;BR /&gt;
RUN;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;/ASSIGNMENT&gt;&lt;/MORE&gt;</description>
      <pubDate>Fri, 10 Apr 2009 17:27:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Issue-with-trying-to-clean-a-variable-with-different-date/m-p/17211#M3248</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-04-10T17:27:37Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with trying to clean a variable with different date layouts</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Issue-with-trying-to-clean-a-variable-with-different-date/m-p/17212#M3249</link>
      <description>Scott,&lt;BR /&gt;
That example works good but i'm not sure it will work in my case.&lt;BR /&gt;
I have lengths from 1-10 with all different layouts for example&lt;BR /&gt;
I have &lt;BR /&gt;
11/11/54&lt;BR /&gt;
5/9/1978&lt;BR /&gt;
7/23/983&lt;BR /&gt;
9-1-1918&lt;BR /&gt;
7.5.1967&lt;BR /&gt;
11-26-47&lt;BR /&gt;
1.1.1990&lt;BR /&gt;
etc.&lt;BR /&gt;
&lt;BR /&gt;
There are so many variations of the data I would still have to do if statements for each case correct?  Sometimes I have 1 or 2 digit months and days and year is either 2,3 or 4 characters.&lt;BR /&gt;
&lt;BR /&gt;
Thanks for the example &lt;BR /&gt;
Jerry</description>
      <pubDate>Fri, 10 Apr 2009 18:46:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Issue-with-trying-to-clean-a-variable-with-different-date/m-p/17212#M3249</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-04-10T18:46:04Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with trying to clean a variable with different date layouts</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Issue-with-trying-to-clean-a-variable-with-different-date/m-p/17213#M3250</link>
      <description>Given the example data shown, my recommendation is to parse the string (as a single SAS character variable) using the SAS SCAN function, into MONTH, DAY and YEAR (as individual SAS numeric variables).  &lt;BR /&gt;
&lt;BR /&gt;
Here's a tip: if you declare your SAS numeric variables ahead of the SCAN assignment statement, you will get SAS to automatically convert them from character to numeric.  Then use the MDY function to assign your SAS numeric DATE variable.&lt;BR /&gt;
&lt;BR /&gt;
There is another approach where you could use the INPUT function with the various INFORMATs, but I would recommend against using the "too flexible for my palate" ANYDTDTE INFORMAT.  And be sure that you test your values for reasonableness (either with PROC PRINT or PUTLOG to the SASLOG) to ensure that the outputs are desired relative to each date input string.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Fri, 10 Apr 2009 20:24:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Issue-with-trying-to-clean-a-variable-with-different-date/m-p/17213#M3250</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-04-10T20:24:23Z</dc:date>
    </item>
  </channel>
</rss>

