<?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: Replacing Missing Values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Replacing-Missing-Values/m-p/272071#M310769</link>
    <description>&lt;P&gt;The method is&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Identify records with last characters that are ".."&lt;/P&gt;
&lt;P&gt;2. If 1 is true, remove periods and use input function to convert to a SAS date&lt;/P&gt;
&lt;P&gt;3. If 1 is false, use input to convert to a SAS date&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Part that was missing is remove the periods from the character variable. This is why sample data in your first post is so important.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data TEST;
input oldvar $8.;
if substr(oldvar, 7, 2) = ".." then do;
newvar = input(substr(oldvar, 1, 6) || '01',yymmdd8.);
newvar = intnx('month',newvar,0,'end');
end;
else newvar = input(oldvar,yymmdd8.);
format newvar yymmdd8.;
datalines;
20160520
201505..
19970116
199901..
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 20 May 2016 18:08:26 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2016-05-20T18:08:26Z</dc:date>
    <item>
      <title>Replacing Missing Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-Missing-Values/m-p/271899#M310757</link>
      <description>&lt;P&gt;Hello Community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a large data set that consists of a number of dates in the format yyymmdd. &amp;nbsp;Some values are missing the day portion only. &amp;nbsp;Is there one functon in SAS that can allow to replace these missing values by the last day of a given month?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Fri, 20 May 2016 05:15:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-Missing-Values/m-p/271899#M310757</guid>
      <dc:creator>Stat_1</dc:creator>
      <dc:date>2016-05-20T05:15:48Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing Missing Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-Missing-Values/m-p/271911#M310758</link>
      <description>&lt;P&gt;I guess your variable is still of type char, containing a maximum of 8 characters?&lt;/P&gt;
&lt;P&gt;So, how about this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if length(oldvar) = 6
then do;
  newvar = input(trim(oldvar) !! '01',yymmdd8.);
  newvar = intnx('month',newvar,0,'end');
end;
else newvar = input(oldvar,yymmdd8.);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 20 May 2016 06:21:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-Missing-Values/m-p/271911#M310758</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-05-20T06:21:46Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing Missing Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-Missing-Values/m-p/271923#M310759</link>
      <description>&lt;P&gt;Make sure to format the variable so it appears the way you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;format new_var yymmdd8.;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 20 May 2016 08:51:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-Missing-Values/m-p/271923#M310759</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-05-20T08:51:25Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing Missing Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-Missing-Values/m-p/271925#M310760</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Make sure to format the variable so it appears the way you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;format new_var yymmdd8.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yeah, right. It's something that I tend to leave as an exercise for the dear reader&amp;amp;student &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 20 May 2016 09:03:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-Missing-Values/m-p/271925#M310760</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-05-20T09:03:29Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing Missing Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-Missing-Values/m-p/271953#M310761</link>
      <description>&lt;P&gt;This is a good example of substr function of the left side of equal. &amp;nbsp;Insert the non-missing date parts into a date of your choosing. &amp;nbsp;I don't know if you want to go all the way to and insert missing year but you can.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dates;
   input cdate :$8.;
   newdate = '20160101';
   if not missing(cdate) then substr(newdate,1,length(cdate))=cdate;
   sasdate = input(newdate,yymmdd8.);
   format sasdate yymmddn.;
   cards;
20160520
201505
2016
.
;;;;
   run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/3258i4632E9110B4666F7/image-size/original?v=v2&amp;amp;px=-1" border="0" alt="Capture.PNG" title="Capture.PNG" /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 20 May 2016 12:03:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-Missing-Values/m-p/271953#M310761</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2016-05-20T12:03:30Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing Missing Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-Missing-Values/m-p/272052#M310762</link>
      <description>&lt;P&gt;Thank you. What if the last 2 digits for a day had the following ".." instead of nothing? How can I make this work? I also wanted to name the complete dates another name to be able to keep track of what is the real input, and what is corrected.&lt;/P&gt;&lt;P&gt;Thank you again!&lt;/P&gt;</description>
      <pubDate>Fri, 20 May 2016 17:32:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-Missing-Values/m-p/272052#M310762</guid>
      <dc:creator>Stat_1</dc:creator>
      <dc:date>2016-05-20T17:32:18Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing Missing Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-Missing-Values/m-p/272054#M310763</link>
      <description>&lt;P&gt;Then change your IF condition to check that the last two characters are ".." rather than the current condition which checks for length.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if substr(date, 7, 2) = ".." then do;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 20 May 2016 17:34:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-Missing-Values/m-p/272054#M310763</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-05-20T17:34:30Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing Missing Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-Missing-Values/m-p/272057#M310764</link>
      <description>&lt;P&gt;Thank you. I still get errors thougth. &amp;nbsp;The missing dates look like that 201605..&lt;/P&gt;</description>
      <pubDate>Fri, 20 May 2016 17:41:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-Missing-Values/m-p/272057#M310764</guid>
      <dc:creator>Stat_1</dc:creator>
      <dc:date>2016-05-20T17:41:03Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing Missing Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-Missing-Values/m-p/272059#M310765</link>
      <description>&lt;P&gt;Post your code and a sample of your data and expected output.&lt;/P&gt;</description>
      <pubDate>Fri, 20 May 2016 17:42:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-Missing-Values/m-p/272059#M310765</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-05-20T17:42:41Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing Missing Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-Missing-Values/m-p/272062#M310766</link>
      <description>&lt;P&gt;Thank you. What if I wanted to replace with the last day of given month?&lt;/P&gt;</description>
      <pubDate>Fri, 20 May 2016 17:44:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-Missing-Values/m-p/272062#M310766</guid>
      <dc:creator>Stat_1</dc:creator>
      <dc:date>2016-05-20T17:44:00Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing Missing Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-Missing-Values/m-p/272068#M310768</link>
      <description>&lt;P&gt;Please see the example below. Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data TEST;&lt;BR /&gt;input oldvar $;&lt;BR /&gt;if substr(oldvar, 7, 2) = ".." then do;&lt;BR /&gt;newvar = input(trim(oldvar) !! '01',yymmdd8.);&lt;BR /&gt;newvar = intnx('month',newvar,0,'end');&lt;BR /&gt;end;&lt;BR /&gt;else newvar = input(oldvar,yymmdd8.);&lt;BR /&gt;format newvar yymmdd8.;&lt;/P&gt;&lt;P&gt;datalines;&lt;BR /&gt;20160520&lt;BR /&gt;201505..&lt;BR /&gt;19970116&lt;BR /&gt;199901..&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 20 May 2016 18:00:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-Missing-Values/m-p/272068#M310768</guid>
      <dc:creator>Stat_1</dc:creator>
      <dc:date>2016-05-20T18:00:12Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing Missing Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-Missing-Values/m-p/272071#M310769</link>
      <description>&lt;P&gt;The method is&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Identify records with last characters that are ".."&lt;/P&gt;
&lt;P&gt;2. If 1 is true, remove periods and use input function to convert to a SAS date&lt;/P&gt;
&lt;P&gt;3. If 1 is false, use input to convert to a SAS date&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Part that was missing is remove the periods from the character variable. This is why sample data in your first post is so important.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data TEST;
input oldvar $8.;
if substr(oldvar, 7, 2) = ".." then do;
newvar = input(substr(oldvar, 1, 6) || '01',yymmdd8.);
newvar = intnx('month',newvar,0,'end');
end;
else newvar = input(oldvar,yymmdd8.);
format newvar yymmdd8.;
datalines;
20160520
201505..
19970116
199901..
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 20 May 2016 18:08:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-Missing-Values/m-p/272071#M310769</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-05-20T18:08:26Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing Missing Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-Missing-Values/m-p/272115#M310770</link>
      <description>Thank you for your help. Is there a way to keep track of dates that have been adjusted?</description>
      <pubDate>Fri, 20 May 2016 19:42:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-Missing-Values/m-p/272115#M310770</guid>
      <dc:creator>Stat_1</dc:creator>
      <dc:date>2016-05-20T19:42:08Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing Missing Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-Missing-Values/m-p/272122#M310771</link>
      <description>&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 20 May 2016 20:14:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-Missing-Values/m-p/272122#M310771</guid>
      <dc:creator>Stat_1</dc:creator>
      <dc:date>2016-05-20T20:14:22Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing Missing Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-Missing-Values/m-p/272133#M310772</link>
      <description>&lt;P&gt;You could create a variable called flag that gets set to 1 if different and 0 otherwise.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You would set the value in the do loop.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 May 2016 20:22:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-Missing-Values/m-p/272133#M310772</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-05-20T20:22:39Z</dc:date>
    </item>
  </channel>
</rss>

