<?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: Replace missing characters with last non missing character multiple id's. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Replace-missing-characters-with-last-non-missing-character/m-p/787322#M251556</link>
    <description>&lt;P&gt;Well first you need to identify the last quarter with a value for each ID.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data LAST;
&amp;nbsp; set HAVE;
&amp;nbsp; where CHAR ne '..';
&amp;nbsp; by ID YEAR QUARTER;
&amp;nbsp; if last.ID;
&amp;nbsp;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you use that information&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WANT;
 &amp;nbsp; length&amp;nbsp;RETAIN&amp;nbsp;$3;
 &amp;nbsp; retain&amp;nbsp;RETAIN;
   merge HAVE LAST(in=LASTVAL);
&amp;nbsp;  by ID YEAR QUARTER;
&amp;nbsp;  if first.ID then RETAIN='   ';
   if LASTVAL then RETAIN=CHAR ;
  &amp;nbsp;else&amp;nbsp;if RETAIN ne ' ' then&amp;nbsp;CHAR=RETAIN;
 run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 24 Dec 2021 04:46:35 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2021-12-24T04:46:35Z</dc:date>
    <item>
      <title>Replace missing characters with last non missing character multiple id's.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-missing-characters-with-last-non-missing-character/m-p/787190#M251469</link>
      <description>&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am writing a code to replace all missing charcters after the last non missing character with the last non missing character by member id but my code replaces all member ids with the first member id's last non missing character . Each member id is in the data 16 times. Can someone help me on how the code should break once it encounters a new member id and use the new member id's last non missing character to populate all missing characters after the last non-missing character ? I tried the code below by doesn't work. I want to replace the missing characters after the last non missing character with the last non missing character. For example for id 1, missing character after 2019 quarter 1 will have 'abc'. For id 2, missing character after 2018, 4th quarter will have 'ghi' .Snippet of my code is below but it doesn't work.. Your help is appreciated&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;Data want;
input ID FY Qtr Missing_Char $3.
datalines;
1 2018 1 ''
1 2018 2  ''
1 2018 3 ''
1 2018 4 ''
1 2019 1 abc
1 2019 2 ''
1 2019 3 ''
2 2018 1 abc
2 2018 2 ''
2 2018 3 def
2 2018 4 ghi
2 2019 1 ''
2 2019 2 ''
2 2019 3 ''
3 2019 4 ''
;
run&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE class=""&gt;&lt;BR /&gt;Data chk;
 set want;
by id ;
retain missing_char;
 if not missing(missing_char) then _missing_char=missing_char;
else missing_char=_missing_char;
_drop missing_char;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Dec 2021 01:59:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-missing-characters-with-last-non-missing-character/m-p/787190#M251469</guid>
      <dc:creator>Paakay</dc:creator>
      <dc:date>2021-12-23T01:59:09Z</dc:date>
    </item>
    <item>
      <title>Re: Replace missing characters with last non missing character multiple id's.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-missing-characters-with-last-non-missing-character/m-p/787322#M251556</link>
      <description>&lt;P&gt;Well first you need to identify the last quarter with a value for each ID.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data LAST;
&amp;nbsp; set HAVE;
&amp;nbsp; where CHAR ne '..';
&amp;nbsp; by ID YEAR QUARTER;
&amp;nbsp; if last.ID;
&amp;nbsp;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you use that information&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WANT;
 &amp;nbsp; length&amp;nbsp;RETAIN&amp;nbsp;$3;
 &amp;nbsp; retain&amp;nbsp;RETAIN;
   merge HAVE LAST(in=LASTVAL);
&amp;nbsp;  by ID YEAR QUARTER;
&amp;nbsp;  if first.ID then RETAIN='   ';
   if LASTVAL then RETAIN=CHAR ;
  &amp;nbsp;else&amp;nbsp;if RETAIN ne ' ' then&amp;nbsp;CHAR=RETAIN;
 run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Dec 2021 04:46:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-missing-characters-with-last-non-missing-character/m-p/787322#M251556</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-12-24T04:46:35Z</dc:date>
    </item>
  </channel>
</rss>

