<?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: If header consist &amp;quot;date&amp;quot; then convert value in date9. format in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/If-header-consist-quot-date-quot-then-convert-value-in-date9/m-p/447406#M112383</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming you have character dates as input :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
    length date_1 date_2 $10;
    input id date_1 $ date_2 $;
    cards;
1 01/01/2018 05/16/2017
2 02/03/2018 06/25/2016
3 12/21/2017 03/01/2015
;
run;

data _NULL_;
    set have end=eof;

    call execute('data want; set have(rename=(');

    length colname $32;

    do while (upcase(colname) ne "COLNAME");
        call vnext(colname);
        if colname=:"date" then do;
            call execute(cats(colname,'=old_',colname));
        end;
    end;

    call execute('));');

    colname="";

    do while (upcase(colname) ne "COLNAME");
        call vnext(colname);
        if colname=:"date" then do;
            call execute(catx(' ','format',colname,'date9.;',colname,'=input(old_'||colname,', mmddyy10.);'));
        end;
    end;

    call execute('drop old_:; run;');

    stop;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 21 Mar 2018 13:29:39 GMT</pubDate>
    <dc:creator>gamotte</dc:creator>
    <dc:date>2018-03-21T13:29:39Z</dc:date>
    <item>
      <title>If header consist "date" then convert value in date9. format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-header-consist-quot-date-quot-then-convert-value-in-date9/m-p/447391#M112377</link>
      <description>&lt;P&gt;&lt;BR /&gt;I have a dataset, I want to check all the column name and if that consists "Date" in the header then convert that column in date9. format.&lt;/P&gt;&lt;P&gt;the already available date field can be in text format or date format, but they are date.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Mar 2018 12:43:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-header-consist-quot-date-quot-then-convert-value-in-date9/m-p/447391#M112377</guid>
      <dc:creator>Srigyan</dc:creator>
      <dc:date>2018-03-21T12:43:16Z</dc:date>
    </item>
    <item>
      <title>Re: If header consist "date" then convert value in date9. format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-header-consist-quot-date-quot-then-convert-value-in-date9/m-p/447403#M112381</link>
      <description>&lt;P&gt;For an automatic conversion, you have to determine the following&lt;/P&gt;
&lt;P&gt;- is the variable numeric or character?&lt;/P&gt;
&lt;P&gt;- if the first:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;are the contents typical for SAS dates -&amp;gt; only apply a format&lt;/LI&gt;
&lt;LI&gt;are the contents typical for SAS datetimes -&amp;gt; use the datepart() function and apply a format&lt;/LI&gt;
&lt;LI&gt;are the contents actually numbers like 20032018 or 20180320 -&amp;gt; convert with put() and input() functions and apply a format&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;if the latter:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;find out which format is used&lt;/LI&gt;
&lt;LI&gt;convert using the input() function with a proper informat&lt;/LI&gt;
&lt;LI&gt;apply a format&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Metadata (column name, type, currently applied format) can be retrieved from dictionary.columns (or sashelp.vcolumn)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This will be a very tedious task. It is much better to do this type of "cleaning" upon import of data into the SAS system.&lt;/P&gt;
&lt;P&gt;Where does your dataset come from?&lt;/P&gt;</description>
      <pubDate>Wed, 21 Mar 2018 13:14:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-header-consist-quot-date-quot-then-convert-value-in-date9/m-p/447403#M112381</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-03-21T13:14:11Z</dc:date>
    </item>
    <item>
      <title>Re: If header consist "date" then convert value in date9. format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-header-consist-quot-date-quot-then-convert-value-in-date9/m-p/447406#M112383</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming you have character dates as input :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
    length date_1 date_2 $10;
    input id date_1 $ date_2 $;
    cards;
1 01/01/2018 05/16/2017
2 02/03/2018 06/25/2016
3 12/21/2017 03/01/2015
;
run;

data _NULL_;
    set have end=eof;

    call execute('data want; set have(rename=(');

    length colname $32;

    do while (upcase(colname) ne "COLNAME");
        call vnext(colname);
        if colname=:"date" then do;
            call execute(cats(colname,'=old_',colname));
        end;
    end;

    call execute('));');

    colname="";

    do while (upcase(colname) ne "COLNAME");
        call vnext(colname);
        if colname=:"date" then do;
            call execute(catx(' ','format',colname,'date9.;',colname,'=input(old_'||colname,', mmddyy10.);'));
        end;
    end;

    call execute('drop old_:; run;');

    stop;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 21 Mar 2018 13:29:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-header-consist-quot-date-quot-then-convert-value-in-date9/m-p/447406#M112383</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2018-03-21T13:29:39Z</dc:date>
    </item>
  </channel>
</rss>

