<?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: Split a character variable into a character and a date mmdd in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Split-a-character-variable-into-a-character-and-a-date-mmdd/m-p/736025#M80431</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/362958"&gt;@KayeMcK&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks Reeza,&lt;/P&gt;
&lt;P&gt;I do have the year in a different column (2005). I attached the file.&lt;/P&gt;
&lt;P&gt;I tried this code and got the NewDate variable, but only got what I believe is a julian date (19449) in the cells that have a repeated date... Wednesday, Apr 13(1) and Wednesday, Apr 13(2)&lt;/P&gt;
&lt;P&gt;--&lt;/P&gt;
&lt;P&gt;The DOW returned an error.&lt;/P&gt;
&lt;P&gt;--&lt;/P&gt;
&lt;P&gt;data Spring21.DC2;&lt;BR /&gt;set Spring21.chcdata_catcomb;&lt;BR /&gt;NewDate = input(catt(scan(Date,2,","),",2005"),anydtdte.);&lt;BR /&gt;/* DOW = dow(y); */&lt;BR /&gt;proc contents data=spring21.DrewC2;&lt;BR /&gt;run;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You often have to provide an explicit length with anydtdte.&lt;/P&gt;
&lt;P&gt;Consider:&lt;/P&gt;
&lt;PRE&gt;data junk;
   date= "Friday, April 8";
   NewDate = input(catx(',',scan(Date,2,","),"2005"),anydtdte21.);   
   put  newdate date9.;
run;
&lt;/PRE&gt;
&lt;P&gt;since CATX strips trailing spaces like CATT and is designed to insert a string between values I prefer that but the key bit is the length of anydtdte format because it will default to 9 characters which is not enough to read a text month, day of month and a couple of spaces or commas plus the year.&lt;/P&gt;</description>
    <pubDate>Wed, 21 Apr 2021 16:36:43 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2021-04-21T16:36:43Z</dc:date>
    <item>
      <title>Split a character variable into a character and a date mmdd</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Split-a-character-variable-into-a-character-and-a-date-mmdd/m-p/735987#M80426</link>
      <description>&lt;P&gt;I have a file where my date came in as a character and I need to make it a date to use it in Forecasting.&lt;/P&gt;&lt;P&gt;My variable date looks like this:&lt;/P&gt;&lt;P&gt;Friday, April 8&lt;/P&gt;&lt;P&gt;Saturday, April 9&lt;/P&gt;&lt;P&gt;Sunday, April 10&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;What code would I use to make a character variable for DOW and a second variable for the date mmdd?&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;K-&lt;/P&gt;</description>
      <pubDate>Wed, 21 Apr 2021 14:29:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Split-a-character-variable-into-a-character-and-a-date-mmdd/m-p/735987#M80426</guid>
      <dc:creator>KayeMcK</dc:creator>
      <dc:date>2021-04-21T14:29:44Z</dc:date>
    </item>
    <item>
      <title>Re: Split a character variable into a character and a date mmdd</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Split-a-character-variable-into-a-character-and-a-date-mmdd/m-p/735990#M80427</link>
      <description>Do you have a year component? Did you try ANYDTDTE?&lt;BR /&gt;&lt;BR /&gt;If not, add a year component and give that a try:&lt;BR /&gt;&lt;BR /&gt;x = input(catt(orig_variable, ", 2021"), anydtdte.);&lt;BR /&gt;&lt;BR /&gt;Otherwise, the SCAN() function will separate the components. &lt;BR /&gt;&lt;BR /&gt;date = input(catt(scan(orig_variable, 2, ","), ", 2021"), anydtdte.);&lt;BR /&gt;DOW = dow(y);</description>
      <pubDate>Wed, 21 Apr 2021 14:34:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Split-a-character-variable-into-a-character-and-a-date-mmdd/m-p/735990#M80427</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-04-21T14:34:35Z</dc:date>
    </item>
    <item>
      <title>Re: Split a character variable into a character and a date mmdd</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Split-a-character-variable-into-a-character-and-a-date-mmdd/m-p/736002#M80428</link>
      <description>&lt;P&gt;Thanks Reeza,&lt;/P&gt;&lt;P&gt;I do have the year in a different column (2005). I attached the file.&lt;/P&gt;&lt;P&gt;I tried this code and got the NewDate variable, but only got what I believe is a julian date (19449) in the cells that have a repeated date... Wednesday, Apr 13(1) and Wednesday, Apr 13(2)&lt;/P&gt;&lt;P&gt;--&lt;/P&gt;&lt;P&gt;The DOW returned an error.&lt;/P&gt;&lt;P&gt;--&lt;/P&gt;&lt;P&gt;data Spring21.DC2;&lt;BR /&gt;set Spring21.chcdata_catcomb;&lt;BR /&gt;NewDate = input(catt(scan(Date,2,","),",2005"),anydtdte.);&lt;BR /&gt;/* DOW = dow(y); */&lt;BR /&gt;proc contents data=spring21.DrewC2;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Apr 2021 14:50:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Split-a-character-variable-into-a-character-and-a-date-mmdd/m-p/736002#M80428</guid>
      <dc:creator>KayeMcK</dc:creator>
      <dc:date>2021-04-21T14:50:51Z</dc:date>
    </item>
    <item>
      <title>Re: Split a character variable into a character and a date mmdd</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Split-a-character-variable-into-a-character-and-a-date-mmdd/m-p/736004#M80429</link>
      <description>Sorry, code here...&lt;BR /&gt;data Spring21.DC2;&lt;BR /&gt;set Spring21.chcdata_catcomb;&lt;BR /&gt;NewDate = input(catt(scan(Date,2,","),",2005"),anydtdte.);&lt;BR /&gt;/* DOW = dow(y); */&lt;BR /&gt;proc contents data=spring21.DC2;&lt;BR /&gt;run;</description>
      <pubDate>Wed, 21 Apr 2021 14:51:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Split-a-character-variable-into-a-character-and-a-date-mmdd/m-p/736004#M80429</guid>
      <dc:creator>KayeMcK</dc:creator>
      <dc:date>2021-04-21T14:51:37Z</dc:date>
    </item>
    <item>
      <title>Re: Split a character variable into a character and a date mmdd</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Split-a-character-variable-into-a-character-and-a-date-mmdd/m-p/736019#M80430</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Spring21.DC2;
set Spring21.chcdata_catcomb;
NewDate = input(catt(scan(Date,2,","),",2005"),anydtdte.);
DOW = dow(newDate); 
dayofweek = scan(date, 1, ",");
format newDate yymmdd10.;
run;

proc contents data=spring21.DrewC2;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 21 Apr 2021 15:18:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Split-a-character-variable-into-a-character-and-a-date-mmdd/m-p/736019#M80430</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-04-21T15:18:25Z</dc:date>
    </item>
    <item>
      <title>Re: Split a character variable into a character and a date mmdd</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Split-a-character-variable-into-a-character-and-a-date-mmdd/m-p/736025#M80431</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/362958"&gt;@KayeMcK&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks Reeza,&lt;/P&gt;
&lt;P&gt;I do have the year in a different column (2005). I attached the file.&lt;/P&gt;
&lt;P&gt;I tried this code and got the NewDate variable, but only got what I believe is a julian date (19449) in the cells that have a repeated date... Wednesday, Apr 13(1) and Wednesday, Apr 13(2)&lt;/P&gt;
&lt;P&gt;--&lt;/P&gt;
&lt;P&gt;The DOW returned an error.&lt;/P&gt;
&lt;P&gt;--&lt;/P&gt;
&lt;P&gt;data Spring21.DC2;&lt;BR /&gt;set Spring21.chcdata_catcomb;&lt;BR /&gt;NewDate = input(catt(scan(Date,2,","),",2005"),anydtdte.);&lt;BR /&gt;/* DOW = dow(y); */&lt;BR /&gt;proc contents data=spring21.DrewC2;&lt;BR /&gt;run;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You often have to provide an explicit length with anydtdte.&lt;/P&gt;
&lt;P&gt;Consider:&lt;/P&gt;
&lt;PRE&gt;data junk;
   date= "Friday, April 8";
   NewDate = input(catx(',',scan(Date,2,","),"2005"),anydtdte21.);   
   put  newdate date9.;
run;
&lt;/PRE&gt;
&lt;P&gt;since CATX strips trailing spaces like CATT and is designed to insert a string between values I prefer that but the key bit is the length of anydtdte format because it will default to 9 characters which is not enough to read a text month, day of month and a couple of spaces or commas plus the year.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Apr 2021 16:36:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Split-a-character-variable-into-a-character-and-a-date-mmdd/m-p/736025#M80431</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-04-21T16:36:43Z</dc:date>
    </item>
    <item>
      <title>Re: Split a character variable into a character and a date mmdd</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Split-a-character-variable-into-a-character-and-a-date-mmdd/m-p/736031#M80432</link>
      <description>&lt;P&gt;Thank you so much.&lt;/P&gt;&lt;P&gt;I am almost there!&lt;/P&gt;&lt;P&gt;I have some dates that were appended with a (1) or a (2). I just need to strip that off before adding the year. Everything else is working!&lt;/P&gt;&lt;P&gt;the anydtdte21. the "21" is what fixed the last error I was having.&lt;/P&gt;&lt;P&gt;K-&lt;/P&gt;</description>
      <pubDate>Wed, 21 Apr 2021 15:41:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Split-a-character-variable-into-a-character-and-a-date-mmdd/m-p/736031#M80432</guid>
      <dc:creator>KayeMcK</dc:creator>
      <dc:date>2021-04-21T15:41:41Z</dc:date>
    </item>
    <item>
      <title>Re: Split a character variable into a character and a date mmdd</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Split-a-character-variable-into-a-character-and-a-date-mmdd/m-p/736043#M80433</link>
      <description>Thanks again !!!&lt;BR /&gt;It may be rough, but I split the variable again and it works!!!&lt;BR /&gt;THANK YOU!!!&lt;BR /&gt;&lt;BR /&gt;data DC2;&lt;BR /&gt;set chcdata_catcomb;&lt;BR /&gt;Date1 = scan(Date,2,",");&lt;BR /&gt;Date2 = scan(Date1,1,"(");&lt;BR /&gt;NewDate = input(catt(Date2,",2005"),anydtdte21.);&lt;BR /&gt;dayofweek = scan(date, 1, ",");&lt;BR /&gt;format NewDate yymmdd10.;&lt;BR /&gt;run;&lt;BR /&gt;proc contents data=DC2;&lt;BR /&gt;run;</description>
      <pubDate>Wed, 21 Apr 2021 15:48:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Split-a-character-variable-into-a-character-and-a-date-mmdd/m-p/736043#M80433</guid>
      <dc:creator>KayeMcK</dc:creator>
      <dc:date>2021-04-21T15:48:08Z</dc:date>
    </item>
  </channel>
</rss>

