<?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: How to read date in multiple formats? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-date-in-multiple-formats/m-p/743658#M232871</link>
    <description>&lt;P&gt;Your DATE values don't look too bad.&amp;nbsp; They all appear to be in MDY order.&amp;nbsp; So use the MMDDYY. informat.&lt;/P&gt;
&lt;P&gt;Your NAME field is going to be a problem however.&amp;nbsp; Your examples do not have any way to tell where the NAME ends and where the TypeOfExposure field starts.&amp;nbsp; If the last field can only ever be one word then you might be able to find a way to read the data even if some names had three (or four or one) words.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  infile cards truncover ;
  length PersonID Exp_Date OriginCaseID 8 Name $80 TypeofExposure $20; 
  input PersonID Exp_Date OriginCaseID Name $80. ;
  TypeofExposure = scan(name,-1,' ');
  name = substrn(name,1,length(name)-length(typeofexposure));
  informat exp_date mmddyy.;
  format exp_date yymmdd10. ;
cards;
1 12/20/20 100 Joe Smith Household
1 9/30/20 135 Joe Smith Workplace
2 1/5/21 168 Maria Rojas Education
3 11/4/20 96 Mary Hernandez Workplace
3 11/4/20 121 Mary Hernandez Workplace
3 1/25/21 365 Mary Hernandez Household
;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;results&lt;/P&gt;
&lt;PRE&gt;       Person                  Origin                       Typeof
Obs      ID        Exp_Date    CaseID    Name              Exposure

 1        1      2020-12-20      100     Joe Smith         Household
 2        1      2020-09-30      135     Joe Smith         Workplace
 3        2      2021-01-05      168     Maria Rojas       Education
 4        3      2020-11-04       96     Mary Hernandez    Workplace
 5        3      2020-11-04      121     Mary Hernandez    Workplace
 6        3      2021-01-25      365     Mary Hernandez    Household
&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 26 May 2021 16:53:52 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-05-26T16:53:52Z</dc:date>
    <item>
      <title>How to read date in multiple formats?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-date-in-multiple-formats/m-p/743638#M232866</link>
      <description>&lt;P&gt;How to read this data? Date in multiple formats?&lt;/P&gt;
&lt;P&gt;Person ID Exp_Date&amp;nbsp; Origin Case ID Name Type of Exposure&lt;BR /&gt;1 12/20/20 100 Joe Smith Household&lt;BR /&gt;1 9/30/20 135 Joe Smith Workplace&lt;BR /&gt;2 1/5/21 168 Maria Rojas Education&lt;BR /&gt;3 11/4/20 96 Mary Hernandez Workplace&lt;BR /&gt;3 11/4/20 121 Mary Hernandez Workplace&lt;BR /&gt;3 1/25/21 365 Mary Hernandez Household&lt;/P&gt;</description>
      <pubDate>Tue, 25 May 2021 17:14:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-read-date-in-multiple-formats/m-p/743638#M232866</guid>
      <dc:creator>rimal_mahesh</dc:creator>
      <dc:date>2021-05-25T17:14:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to read date in multiple formats?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-date-in-multiple-formats/m-p/743645#M232867</link>
      <description>&lt;P&gt;Not seeing multiple formats, can you please elaborate?&lt;BR /&gt;Does an informat of MMDDYY10 not work?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10110"&gt;@rimal_mahesh&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;How to read this data? Date in multiple formats?&lt;/P&gt;
&lt;P&gt;Person ID Exp_Date&amp;nbsp; Origin Case ID Name Type of Exposure&lt;BR /&gt;1 12/20/20 100 Joe Smith Household&lt;BR /&gt;1 9/30/20 135 Joe Smith Workplace&lt;BR /&gt;2 1/5/21 168 Maria Rojas Education&lt;BR /&gt;3 11/4/20 96 Mary Hernandez Workplace&lt;BR /&gt;3 11/4/20 121 Mary Hernandez Workplace&lt;BR /&gt;3 1/25/21 365 Mary Hernandez Household&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 May 2021 17:44:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-read-date-in-multiple-formats/m-p/743645#M232867</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-05-25T17:44:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to read date in multiple formats?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-date-in-multiple-formats/m-p/743653#M232869</link>
      <description>&lt;P&gt;This&lt;/P&gt;
&lt;PRE&gt;11/4/20&lt;/PRE&gt;
&lt;P&gt;might be&lt;/P&gt;
&lt;PRE&gt;2020-04--11
2020-11-04
2011-04-20
1920-04-11
1920-11-04
1911-04-20&lt;/PRE&gt;
&lt;P&gt;to state just a few of the possible dates.&lt;/P&gt;
&lt;P&gt;Even if you know the source data is in MDY order, it is still ambiguous with regards to the century.&lt;/P&gt;
&lt;P&gt;Using 2-digit years is extremely stupid.&lt;/P&gt;
&lt;P&gt;So I would return this garbage to sender and request&amp;nbsp;&lt;U&gt;data&lt;/U&gt; instead.&lt;/P&gt;</description>
      <pubDate>Tue, 25 May 2021 18:15:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-read-date-in-multiple-formats/m-p/743653#M232869</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-05-25T18:15:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to read date in multiple formats?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-date-in-multiple-formats/m-p/743658#M232871</link>
      <description>&lt;P&gt;Your DATE values don't look too bad.&amp;nbsp; They all appear to be in MDY order.&amp;nbsp; So use the MMDDYY. informat.&lt;/P&gt;
&lt;P&gt;Your NAME field is going to be a problem however.&amp;nbsp; Your examples do not have any way to tell where the NAME ends and where the TypeOfExposure field starts.&amp;nbsp; If the last field can only ever be one word then you might be able to find a way to read the data even if some names had three (or four or one) words.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  infile cards truncover ;
  length PersonID Exp_Date OriginCaseID 8 Name $80 TypeofExposure $20; 
  input PersonID Exp_Date OriginCaseID Name $80. ;
  TypeofExposure = scan(name,-1,' ');
  name = substrn(name,1,length(name)-length(typeofexposure));
  informat exp_date mmddyy.;
  format exp_date yymmdd10. ;
cards;
1 12/20/20 100 Joe Smith Household
1 9/30/20 135 Joe Smith Workplace
2 1/5/21 168 Maria Rojas Education
3 11/4/20 96 Mary Hernandez Workplace
3 11/4/20 121 Mary Hernandez Workplace
3 1/25/21 365 Mary Hernandez Household
;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;results&lt;/P&gt;
&lt;PRE&gt;       Person                  Origin                       Typeof
Obs      ID        Exp_Date    CaseID    Name              Exposure

 1        1      2020-12-20      100     Joe Smith         Household
 2        1      2020-09-30      135     Joe Smith         Workplace
 3        2      2021-01-05      168     Maria Rojas       Education
 4        3      2020-11-04       96     Mary Hernandez    Workplace
 5        3      2020-11-04      121     Mary Hernandez    Workplace
 6        3      2021-01-25      365     Mary Hernandez    Household
&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 May 2021 16:53:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-read-date-in-multiple-formats/m-p/743658#M232871</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-05-26T16:53:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to read date in multiple formats?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-date-in-multiple-formats/m-p/743681#M232885</link>
      <description>Thank you Works Perfectly.&lt;BR /&gt;</description>
      <pubDate>Tue, 25 May 2021 19:40:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-read-date-in-multiple-formats/m-p/743681#M232885</guid>
      <dc:creator>rimal_mahesh</dc:creator>
      <dc:date>2021-05-25T19:40:06Z</dc:date>
    </item>
  </channel>
</rss>

