<?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: Mass apply mmddyy10. format to all date variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Mass-apply-mmddyy10-format-to-all-date-variables/m-p/782005#M249265</link>
    <description>&lt;P&gt;NO.&amp;nbsp; But that doesn't mean that YOU have to list them yourself.&amp;nbsp; Let SAS do it for you.&lt;/P&gt;
&lt;P&gt;First let's make a couple of macro variables so we don't have to keep re-typing the name of the dataset. Then we can ask SAS to create another macro variable with the variables we want to change. Then use PROC DATASETS to change the formats.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let lib=WORK;
%let ds=HAVE;
proc contents data=&amp;amp;lib..&amp;amp;ds noprint out=contents; run;
proc sql noprint;
select nliteral(name) into :datevars separated by ' '
  from contents
  where format='YYMMDD'
;
quit;
proc datasets nolist lib=&amp;amp;lib;
  modify &amp;amp;ds ;
    format &amp;amp;datevars mmddyy10.;
  run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;PS Why do you want to convert from a date style that everyone will understand to one that will confuse 50% of the world?&amp;nbsp; Does 10/12/2021 mean October twelfth or the tenth of December?&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 23 Nov 2021 17:12:07 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-11-23T17:12:07Z</dc:date>
    <item>
      <title>Mass apply mmddyy10. format to all date variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Mass-apply-mmddyy10-format-to-all-date-variables/m-p/782000#M249262</link>
      <description>&lt;P&gt;I have a large dataset with several hundred variables that have a&amp;nbsp;YYMMDD10. informat. Is there an easy way to mass apply a MMDDYY10. format to all of these variables without individually listing them each out in a format statement?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Nov 2021 16:49:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Mass-apply-mmddyy10-format-to-all-date-variables/m-p/782000#M249262</guid>
      <dc:creator>mmm7</dc:creator>
      <dc:date>2021-11-23T16:49:44Z</dc:date>
    </item>
    <item>
      <title>Re: Mass apply mmddyy10. format to all date variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Mass-apply-mmddyy10-format-to-all-date-variables/m-p/782003#M249264</link>
      <description>&lt;P&gt;It will come down to how your variables are named, for example in the example below I have assigned DDMMYY10. to date2 without having to specify date2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
	do date1="23NOV2021"d to "28NOV021"d ;
		date2=date1+7 ;
		date3=date2+7 ;
		output ;
	end ;
run ;

data want ;
	set have ;
	format date1-date3 ddmmyy10. ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now if your date variables have non-sequential variable names e.g. dateOne, dateTwo, dateThree then that's going to be more challenging.&lt;/P&gt;
&lt;P&gt;First question would be how do you know any of these variables are date variables and need to be formatted DDMMYY10.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Nov 2021 16:58:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Mass-apply-mmddyy10-format-to-all-date-variables/m-p/782003#M249264</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2021-11-23T16:58:40Z</dc:date>
    </item>
    <item>
      <title>Re: Mass apply mmddyy10. format to all date variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Mass-apply-mmddyy10-format-to-all-date-variables/m-p/782005#M249265</link>
      <description>&lt;P&gt;NO.&amp;nbsp; But that doesn't mean that YOU have to list them yourself.&amp;nbsp; Let SAS do it for you.&lt;/P&gt;
&lt;P&gt;First let's make a couple of macro variables so we don't have to keep re-typing the name of the dataset. Then we can ask SAS to create another macro variable with the variables we want to change. Then use PROC DATASETS to change the formats.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let lib=WORK;
%let ds=HAVE;
proc contents data=&amp;amp;lib..&amp;amp;ds noprint out=contents; run;
proc sql noprint;
select nliteral(name) into :datevars separated by ' '
  from contents
  where format='YYMMDD'
;
quit;
proc datasets nolist lib=&amp;amp;lib;
  modify &amp;amp;ds ;
    format &amp;amp;datevars mmddyy10.;
  run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;PS Why do you want to convert from a date style that everyone will understand to one that will confuse 50% of the world?&amp;nbsp; Does 10/12/2021 mean October twelfth or the tenth of December?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Nov 2021 17:12:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Mass-apply-mmddyy10-format-to-all-date-variables/m-p/782005#M249265</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-11-23T17:12:07Z</dc:date>
    </item>
    <item>
      <title>Re: Mass apply mmddyy10. format to all date variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Mass-apply-mmddyy10-format-to-all-date-variables/m-p/782013#M249269</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;! Your code worked great and will save me SO much time!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Nov 2021 17:16:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Mass-apply-mmddyy10-format-to-all-date-variables/m-p/782013#M249269</guid>
      <dc:creator>mmm7</dc:creator>
      <dc:date>2021-11-23T17:16:04Z</dc:date>
    </item>
    <item>
      <title>Re: Mass apply mmddyy10. format to all date variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Mass-apply-mmddyy10-format-to-all-date-variables/m-p/787775#M251774</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;Do you have syntax to clear all formatting EXCEPT for formatted date and time variables?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Dec 2021 13:53:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Mass-apply-mmddyy10-format-to-all-date-variables/m-p/787775#M251774</guid>
      <dc:creator>mmm7</dc:creator>
      <dc:date>2021-12-30T13:53:26Z</dc:date>
    </item>
    <item>
      <title>Re: Mass apply mmddyy10. format to all date variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Mass-apply-mmddyy10-format-to-all-date-variables/m-p/787784#M251780</link>
      <description>&lt;P&gt;Use the same code, just add an extra FORMAT statement in the last step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc datasets nolist lib=&amp;amp;lib;
  modify &amp;amp;ds ;
    format _all_ ;
    format &amp;amp;datevars mmddyy10.;
  run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 30 Dec 2021 15:06:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Mass-apply-mmddyy10-format-to-all-date-variables/m-p/787784#M251780</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-12-30T15:06:38Z</dc:date>
    </item>
    <item>
      <title>Re: Mass apply mmddyy10. format to all date variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Mass-apply-mmddyy10-format-to-all-date-variables/m-p/787785#M251781</link>
      <description>&lt;P&gt;To find DATE, TIME or DATETIME variables to exclude or re-attach formats to use the &lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/n08tazkeygnw9on138axalvpy9p4.htm" target="_self"&gt;FMTINFO() function&lt;/A&gt; with the 'CAT' info type.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select nliteral(name) into :othervars separated by ' '
  from contents
  where not (fmtinfo(format,'cat') in ('date','time','datetime'))
;
proc datasets nolist lib=&amp;amp;lib;
  modify &amp;amp;ds ;
    format &amp;amp;othervars;
  run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 30 Dec 2021 15:14:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Mass-apply-mmddyy10-format-to-all-date-variables/m-p/787785#M251781</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-12-30T15:14:24Z</dc:date>
    </item>
  </channel>
</rss>

