<?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: Create a Macro for correctting date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-a-Macro-for-correctting-date/m-p/545944#M151112</link>
    <description>&lt;P&gt;Are these variables supposed to be actual date values? If so your goal will not work as SAS will not accept a day or month number of 88 for either. You could create a custom format that would display a missing, or possibly better a special missing value as '88/88/8888' but you can not&amp;nbsp;set an actual date value to that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the value is character then describe how you are using the "date" of 88/88/8888 that would be different than using '01/01/8888'.&lt;/P&gt;</description>
    <pubDate>Mon, 25 Mar 2019 20:03:05 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2019-03-25T20:03:05Z</dc:date>
    <item>
      <title>Create a Macro for correctting date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-Macro-for-correctting-date/m-p/545932#M151107</link>
      <description>&lt;P&gt;Hello:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; I have a dataset with&amp;nbsp;10K observations and over 500 variables.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; In this dataset,&amp;nbsp;many variable (see below) with&amp;nbsp;missing&amp;nbsp;date&amp;nbsp;format are not correct, I would like to correct the date from 01/01/8888 to 88/88/8888.&amp;nbsp;&amp;nbsp; I would like to create a macro to correct all of them.&amp;nbsp;&amp;nbsp; I am curious, is there a way to do that?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let DateVars = ReportDate AdmitDate DischargeDate CultureDate ERDate;


%macro MissingDateFormat;

       .
       .
       .

%mend;

%MissingDateFormat;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 25 Mar 2019 19:21:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-Macro-for-correctting-date/m-p/545932#M151107</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2019-03-25T19:21:12Z</dc:date>
    </item>
    <item>
      <title>Re: Create a Macro for correctting date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-Macro-for-correctting-date/m-p/545936#M151109</link>
      <description>&lt;P&gt;Why a macro? Wouldn't an array work just as well and be quicker?&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 my_dates(*) &amp;amp;dateVars;

do i=1 to dim(my_dates);

if my_dates(i) = '01/01/8888' then my_dates(i) = '88/88/8888';

end;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I'm assuming your dates are characters since those are not valid SAS dates.&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/67134"&gt;@ybz12003&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; I have a dataset with&amp;nbsp;10K observations and over 500 variables.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; In this dataset,&amp;nbsp;many variable (see below) with&amp;nbsp;missing&amp;nbsp;date&amp;nbsp;format are not correct, I would like to correct the date from 01/01/8888 to 88/88/8888.&amp;nbsp;&amp;nbsp; I would like to create a macro to correct all of them.&amp;nbsp;&amp;nbsp; I am curious, is there a way to do that?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let DateVars = ReportDate AdmitDate DischargeDate CultureDate ERDate;


%macro MissingDateFormat;

       .
       .
       .

%mend;

%MissingDateFormat;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Mar 2019 19:34:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-Macro-for-correctting-date/m-p/545936#M151109</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-03-25T19:34:08Z</dc:date>
    </item>
    <item>
      <title>Re: Create a Macro for correctting date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-Macro-for-correctting-date/m-p/545944#M151112</link>
      <description>&lt;P&gt;Are these variables supposed to be actual date values? If so your goal will not work as SAS will not accept a day or month number of 88 for either. You could create a custom format that would display a missing, or possibly better a special missing value as '88/88/8888' but you can not&amp;nbsp;set an actual date value to that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the value is character then describe how you are using the "date" of 88/88/8888 that would be different than using '01/01/8888'.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Mar 2019 20:03:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-Macro-for-correctting-date/m-p/545944#M151112</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-03-25T20:03:05Z</dc:date>
    </item>
    <item>
      <title>Re: Create a Macro for correctting date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-Macro-for-correctting-date/m-p/546114#M151164</link>
      <description>&lt;P&gt;All of the date variables are numeric, not character.&amp;nbsp; &amp;nbsp; They are not the actual date, all of them are the unknown date.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Somehow, the system put them as 01/01/8888 instead of 88/88/8888.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2019 12:58:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-Macro-for-correctting-date/m-p/546114#M151164</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2019-03-26T12:58:43Z</dc:date>
    </item>
    <item>
      <title>Re: Create a Macro for correctting date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-Macro-for-correctting-date/m-p/546139#M151171</link>
      <description>&lt;P&gt;It's strange that I use&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if my_dates(i) = '01/01/8888' then my_dates(i) = '88/88/8888';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if my_dates(i) = ' 01/01/8888  then my_dates(i) = 88/88/8888 ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;None of the above could change the date to 88/88/8888.&amp;nbsp; &amp;nbsp;The column attributes&amp;nbsp;show that the variable length is 8 and the format is MMDDYY10.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2019 13:27:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-Macro-for-correctting-date/m-p/546139#M151171</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2019-03-26T13:27:03Z</dc:date>
    </item>
    <item>
      <title>Re: Create a Macro for correctting date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-Macro-for-correctting-date/m-p/546184#M151193</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/67134"&gt;@ybz12003&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;It's strange that I use&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if my_dates(i) = '01/01/8888' then my_dates(i) = '88/88/8888';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if my_dates(i) = ' 01/01/8888  then my_dates(i) = 88/88/8888 ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;None of the above could change the date to 88/88/8888.&amp;nbsp; &amp;nbsp;The column attributes&amp;nbsp;show that the variable length is 8 and the format is MMDDYY10.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;A SAS date literal is specified as 'ddMONyyyy'd or '01Jan2019'd, ergo why it will not work if it's a SAS date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You cannot have a day or month of 88 so if it is a SAS date that isn't a valid date. You need to change your requirements or store your data as characters which will cause other issues.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2019 14:59:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-Macro-for-correctting-date/m-p/546184#M151193</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-03-26T14:59:37Z</dc:date>
    </item>
    <item>
      <title>Re: Create a Macro for correctting date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-Macro-for-correctting-date/m-p/546194#M151198</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/67134"&gt;@ybz12003&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;It's strange that I use&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if my_dates(i) = '01/01/8888' then my_dates(i) = '88/88/8888';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if my_dates(i) = ' 01/01/8888  then my_dates(i) = 88/88/8888 ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;None of the above could change the date to 88/88/8888.&amp;nbsp; &amp;nbsp;The column attributes&amp;nbsp;show that the variable length is 8 and the format is MMDDYY10.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If the variable is of type numeric and has the MMDDYY10. format attached to it then there is no way to store the value you want. The day of the month cannot be 88 and the month of the year cannot be 88.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could define you own format that displays 01JAN8888 using 88/88/8888 instead of 01/01/8888.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format ;
 value mydate 
  '01JAN8888'd = '88/88/8888'
  other=[mmddyy10.]
 ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Let's try it out:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  input date yymmdd10. ;
  rawdate=date;
  mydate=date;
  format date mmddyy10. mydate mydate10.;
cards;
8888-01-01
2018-02-04
;
proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;Obs          date    rawdate    mydate

 1     01/01/8888    2530399    88/88/8888
 2     02/04/2018      21219    02/04/2018&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2019 15:13:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-Macro-for-correctting-date/m-p/546194#M151198</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-03-26T15:13:52Z</dc:date>
    </item>
    <item>
      <title>Re: Create a Macro for correctting date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-Macro-for-correctting-date/m-p/546208#M151201</link>
      <description>&lt;P&gt;Great!&amp;nbsp; The date format code is WORKING!&amp;nbsp; &amp;nbsp;However, how to change all of them in a bunch of variables?&amp;nbsp; I use the array above.&amp;nbsp; It didn't work.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2019 15:35:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-Macro-for-correctting-date/m-p/546208#M151201</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2019-03-26T15:35:33Z</dc:date>
    </item>
    <item>
      <title>Re: Create a Macro for correctting date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-Macro-for-correctting-date/m-p/546209#M151202</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/67134"&gt;@ybz12003&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Great!&amp;nbsp; The date format code is WORKING!&amp;nbsp; &amp;nbsp;However, how to change all of them in a bunch of variables?&amp;nbsp; I use the array above.&amp;nbsp; It didn't work.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;No need for an array.&lt;/P&gt;
&lt;P&gt;You want a FORMAT statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let varlist=date1 date2;

proc datasets lib=mylib nolist;
  modify mydsn ;
  format &amp;amp;varlist mydate10. ;
run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Mar 2019 15:37:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-Macro-for-correctting-date/m-p/546209#M151202</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-03-26T15:37:15Z</dc:date>
    </item>
    <item>
      <title>Re: Create a Macro for correctting date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-Macro-for-correctting-date/m-p/546212#M151203</link>
      <description>&lt;P&gt;Yet another reason to supply example data in the form of a data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With proper example data the first response would likely have covered this issue.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2019 15:44:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-Macro-for-correctting-date/m-p/546212#M151203</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-03-26T15:44:11Z</dc:date>
    </item>
    <item>
      <title>Re: Create a Macro for correctting date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-Macro-for-correctting-date/m-p/546244#M151218</link>
      <description>&lt;P&gt;Amazing!&amp;nbsp; &amp;nbsp;Thanks, Tom.&amp;nbsp; The codes work!&amp;nbsp; &amp;nbsp;One last Q, when I use PROC DATASET, is there a way to output the modified dataset into a new dataset,&amp;nbsp; or it could only use the same name?&amp;nbsp; &amp;nbsp;If not, don't worry about.&amp;nbsp; &amp;nbsp;It's not a big deal.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2019 17:21:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-Macro-for-correctting-date/m-p/546244#M151218</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2019-03-26T17:21:24Z</dc:date>
    </item>
    <item>
      <title>Re: Create a Macro for correctting date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-Macro-for-correctting-date/m-p/546245#M151219</link>
      <description>If you want to make a new dataset just add the FORMAT statement to the data step.&lt;BR /&gt;data new; set old; format &amp;amp;varlist mydate10.; run;&lt;BR /&gt;</description>
      <pubDate>Tue, 26 Mar 2019 17:25:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-Macro-for-correctting-date/m-p/546245#M151219</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-03-26T17:25:26Z</dc:date>
    </item>
    <item>
      <title>Re: Create a Macro for correctting date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-Macro-for-correctting-date/m-p/546314#M151243</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/67134"&gt;@ybz12003&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Amazing!&amp;nbsp; &amp;nbsp;Thanks, Tom.&amp;nbsp; The codes work!&amp;nbsp; &amp;nbsp;One last Q, when I use PROC DATASET, is there a way to output the modified dataset into a new dataset,&amp;nbsp; or it could only use the same name?&amp;nbsp; &amp;nbsp;If not, don't worry about.&amp;nbsp; &amp;nbsp;It's not a big deal.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Proc datasets will also copy data sets. So try copy and then modify the copy. Or modify the set and then create a copy. Choice is yours. Depends on what you want for contents.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2019 21:14:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-Macro-for-correctting-date/m-p/546314#M151243</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-03-26T21:14:37Z</dc:date>
    </item>
  </channel>
</rss>

