<?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: How to replace missing value in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-to-replace-missing-value/m-p/504174#M926</link>
    <description>&lt;P&gt;Thank you for your help, you may misunderstand my request.&amp;nbsp;&lt;img id="womanwink" class="emoticon emoticon-womanwink" src="https://communities.sas.com/i/smilies/16x16_woman-wink.png" alt="Woman Wink" title="Woman Wink" /&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 15 Oct 2018 03:01:26 GMT</pubDate>
    <dc:creator>Fangfang</dc:creator>
    <dc:date>2018-10-15T03:01:26Z</dc:date>
    <item>
      <title>How to replace missing value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-replace-missing-value/m-p/503625#M850</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
input ID$ Month$ Treatment$ NEW_Treatment$ ;
cards;
1 Month_1 . Missing
1 Month_2 . Missing
1 Month_3 A A
1 Month_4 . Untrt
1 Month_5 B B
1 Month_6 . Untrt
1 Month_7 C C
1 Month_8 . Untrt
1 Month_9 . Untrt
1 Month_10 . Untrt
1 Month_11 E E
1 Month_12 . Untrt
2 Month_1 B B
2 Month_2 C C
2 Month_3 . Untrt
2 Month_4 D D
2 Month_5 . Untrt
2 Month_6 . Untrt
2 Month_7 . Untrt
2 Month_8 . Untrt
2 Month_9 E E
2 Month_10 . Untrt
2 Month_11 . Untrt
2 Month_12 A A
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My current data looks like this， each ID has 12 months' Treatment (from Month_1 to Month_12). I want to replace the Treatment to NEW_treatment，namely, for each ID，the missing records before the first non-missing Treatment will be replaced as 'Missing', the missing records after the first non-missing Treatment will be replaced as 'Untrt'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I am not sure how to do that. Any idea? Thanks!!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Oct 2018 05:59:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-replace-missing-value/m-p/503625#M850</guid>
      <dc:creator>Fangfang</dc:creator>
      <dc:date>2018-10-12T05:59:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to replace missing value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-replace-missing-value/m-p/503661#M856</link>
      <description>&lt;P&gt;Hello Dear,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If i got your request correctly , here you can go ..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data want;
set have;
if  missing (Treatment) then Treatment='Missing';
else Treatment='Untrt';
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;otherwise please share a sample output for further answers..&lt;/P&gt;</description>
      <pubDate>Fri, 12 Oct 2018 09:44:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-replace-missing-value/m-p/503661#M856</guid>
      <dc:creator>singhsahab</dc:creator>
      <dc:date>2018-10-12T09:44:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to replace missing value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-replace-missing-value/m-p/503726#M861</link>
      <description>&lt;P&gt;This should take care of it.&amp;nbsp; It assumes your data is sorted:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;by ID;&lt;/P&gt;
&lt;P&gt;if first.ID then replacement = 'Missing';&lt;/P&gt;
&lt;P&gt;if treatment &amp;gt; ' ' then replacement = 'Untrt';&lt;/P&gt;
&lt;P&gt;retain replacement;&lt;/P&gt;
&lt;P&gt;if treatment = ' ' then new_treatment = replacement;&lt;/P&gt;
&lt;P&gt;else new_treatment = treatment;&lt;/P&gt;
&lt;P&gt;drop replacement;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Oct 2018 13:31:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-replace-missing-value/m-p/503726#M861</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-10-12T13:31:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to replace missing value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-replace-missing-value/m-p/504174#M926</link>
      <description>&lt;P&gt;Thank you for your help, you may misunderstand my request.&amp;nbsp;&lt;img id="womanwink" class="emoticon emoticon-womanwink" src="https://communities.sas.com/i/smilies/16x16_woman-wink.png" alt="Woman Wink" title="Woman Wink" /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Oct 2018 03:01:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-replace-missing-value/m-p/504174#M926</guid>
      <dc:creator>Fangfang</dc:creator>
      <dc:date>2018-10-15T03:01:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to replace missing value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-replace-missing-value/m-p/504227#M935</link>
      <description>&lt;P&gt;Many thanks for your help. As I am a new SAS learner, I can not use your program flexibly; therefore, I have another question: For each ID, I want to replace the missing records before the first non-missing Treatment as 'Missing'; to replace missing records after the last non-missing Treatment as 'Discontinue'; to replace the missing records between the first non-missing Treatment and the last non-missing Treatment as 'Untrt'. Could you please give me a hand again? Thank you in advance.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Oct 2018 08:20:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-replace-missing-value/m-p/504227#M935</guid>
      <dc:creator>Fangfang</dc:creator>
      <dc:date>2018-10-15T08:20:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to replace missing value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-replace-missing-value/m-p/504267#M943</link>
      <description>&lt;P&gt;It can be done, but the programming becomes more complex.&amp;nbsp; You need to locate the last non-missing value.&amp;nbsp; As long as you are doing that, you might as well locate the first non-missing value as well.&amp;nbsp; For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;ID_counter=0;&lt;/P&gt;
&lt;P&gt;do until (last.id);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;by ID;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;ID_counter + 1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;if first_nonmissing = . and treatment &amp;gt; ' ' then first_nonmissing = ID_counter;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;if treatment &amp;gt; ' ' then last_nonmissing = ID_counter;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;ID_counter = 0;&lt;/P&gt;
&lt;P&gt;do until (last.ID);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;by ID;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;ID_counter + 1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;if treatment = ' ' then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; if ID_counter &amp;lt; first_nonmissing then treatment = 'Missing';&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; else if ID_counter &amp;lt; last_nonmissing then treatment = 'Discontinue';&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; else treatment = 'Untrt';&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;output;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;drop first_nonmissing last_nonmissing ID_counter;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The top DO loop reads all the observations for an ID, numbers them, and captures where it finds the first and last non-missing values.&amp;nbsp; Then the second DO loops reads the exact same information and applies the logic for replacing TREATMENT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's&amp;nbsp; untested code, so I will look through a second time to see if I notice anything that needs to be corrected.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that if ALL the treatments are missing, the program will assign "Untrt" for that ID.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Oct 2018 12:40:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-replace-missing-value/m-p/504267#M943</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-10-15T12:40:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to replace missing value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-replace-missing-value/m-p/504566#M992</link>
      <description>&lt;P&gt;Many thanks for your reply and detail explanation.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Based on your codes, I made some minor modifications to&amp;nbsp;&lt;SPAN&gt;assign "Missing" for&amp;nbsp;the ID with&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;ALL the treatments missing.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thank you again.&lt;img id="smileywink" class="emoticon emoticon-smileywink" src="https://communities.sas.com/i/smilies/16x16_smiley-wink.png" alt="Smiley Wink" title="Smiley Wink" /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
ID_counter=0;
do until (last.id);
   set have;
   by ID;
   ID_counter + 1;
   if first_nonmissing = . and Treatment &amp;gt; ' ' then first_nonmissing = ID_counter;
   if Treatment &amp;gt; ' ' then last_nonmissing = ID_counter;
end;

ID_counter = 0;
do until (last.ID);
   set have;
   by ID;
   ID_counter + 1;
   if Treatment = ' ' and first_nonmissing ^= . then do;
      if ID_counter &amp;lt; first_nonmissing then Want_treatment = 'Missing';
      else if ID_counter &amp;gt; last_nonmissing then Want_treatment = 'Discontinue';
      else Want_treatment = 'Untrt';
   end;
   if first_nonmissing = . then do ; Want_treatment = 'Missing';
   end;
   if Treatment ^= ' ' then do;
   	  Want_treatment = Treatment ;
   end ;
   output;
end;
run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 Oct 2018 02:18:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-replace-missing-value/m-p/504566#M992</guid>
      <dc:creator>Fangfang</dc:creator>
      <dc:date>2018-10-16T02:18:16Z</dc:date>
    </item>
  </channel>
</rss>

