<?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: Macro to loop thru all date variables and convert to character type in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-loop-thru-all-date-variables-and-convert-to-character/m-p/486797#M126715</link>
    <description>&lt;P&gt;There's a simpler way than a loop.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just assign the proper format to the date variables, and then when the data is exported somehow, the date variable appear in the selected format.&lt;/P&gt;</description>
    <pubDate>Tue, 14 Aug 2018 19:49:09 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2018-08-14T19:49:09Z</dc:date>
    <item>
      <title>Macro to loop thru all date variables and convert to character type</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-loop-thru-all-date-variables-and-convert-to-character/m-p/486792#M126713</link>
      <description>&lt;P&gt;Is there a way to programmatically loop thru all variables in a dataset and convert any date variables into character variables? I need to push my data to a 3rd party visualization software and it does not like the SAS formatted dates.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This code does the conversion I need, can it be macrotized to automatically convert for every date variable?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data my_dataset;&lt;BR /&gt;set my_dataset;&lt;BR /&gt;if&amp;nbsp;my_date ne . then&lt;BR /&gt;&amp;nbsp;my_date_ch = put(my_date, mmddyy10.);&lt;BR /&gt;else&lt;BR /&gt;&amp;nbsp;my_date_ch = '';&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Aug 2018 19:46:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-loop-thru-all-date-variables-and-convert-to-character/m-p/486792#M126713</guid>
      <dc:creator>SAS_Ryan</dc:creator>
      <dc:date>2018-08-14T19:46:21Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to loop thru all date variables and convert to character type</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-loop-thru-all-date-variables-and-convert-to-character/m-p/486797#M126715</link>
      <description>&lt;P&gt;There's a simpler way than a loop.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just assign the proper format to the date variables, and then when the data is exported somehow, the date variable appear in the selected format.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Aug 2018 19:49:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-loop-thru-all-date-variables-and-convert-to-character/m-p/486797#M126715</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-08-14T19:49:09Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to loop thru all date variables and convert to character type</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-loop-thru-all-date-variables-and-convert-to-character/m-p/486798#M126716</link>
      <description>&lt;P&gt;An array with a loop is likely all you need....if you have a naming convention this is much easier as well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;

array _in(*) list of date variables here;
array _out(*) list of new variables here;

do i=1 to dim(_in);
_out = put(_in(i), ddmmyy10.);
end;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/154659"&gt;@SAS_Ryan&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Is there a way to programmatically loop thru all variables in a dataset and convert any date variables into character variables? I need to push my data to a 3rd party visualization software and it does not like the SAS formatted dates.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This code does the conversion I need, can it be macrotized to automatically convert for every date variable?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data my_dataset;&lt;BR /&gt;set my_dataset;&lt;BR /&gt;if&amp;nbsp;my_date ne . then&lt;BR /&gt;&amp;nbsp;my_date_ch = put(my_date, mmddyy10.);&lt;BR /&gt;else&lt;BR /&gt;&amp;nbsp;my_date_ch = '';&lt;BR /&gt;run;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Aug 2018 19:50:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-loop-thru-all-date-variables-and-convert-to-character/m-p/486798#M126716</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-08-14T19:50:07Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to loop thru all date variables and convert to character type</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-loop-thru-all-date-variables-and-convert-to-character/m-p/486801#M126718</link>
      <description>&lt;P&gt;How many date variables are you talking about? It is likely easier to use a pair of arrays.&lt;/P&gt;
&lt;P&gt;Something like:&lt;/P&gt;
&lt;PRE&gt;data want;
   set my_dataset;
   array d my_date &amp;lt;list other date variables&amp;gt;;
   array c $ 10 my_date_ch &amp;lt;list the new names here&amp;gt;;
   do _i_ = 1 to dim(d);
      if d[i] then c[_i_] = put(d[_i_],mmddyy10.);
   end;
run;&lt;/PRE&gt;
&lt;P&gt;Make sure you have the same number of items in both arrays.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if you set&lt;/P&gt;
&lt;P&gt;options missing=' ';&lt;/P&gt;
&lt;P&gt;you wouldn't even need the test for if the existing date variable isn't missing.&lt;/P&gt;
&lt;P&gt;Do they all have the same format?&lt;/P&gt;</description>
      <pubDate>Tue, 14 Aug 2018 19:57:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-loop-thru-all-date-variables-and-convert-to-character/m-p/486801#M126718</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-08-14T19:57:46Z</dc:date>
    </item>
  </channel>
</rss>

