<?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 retain the values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-the-values/m-p/628713#M185825</link>
    <description>&lt;P&gt;What if you have more than one non-missing value per group, which one should take precedence?&lt;/P&gt;</description>
    <pubDate>Mon, 02 Mar 2020 10:20:50 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-03-02T10:20:50Z</dc:date>
    <item>
      <title>How to retain the values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-the-values/m-p/628699#M185817</link>
      <description>Hello..&lt;BR /&gt;&lt;BR /&gt;I've data..&lt;BR /&gt;&lt;BR /&gt;Data new;&lt;BR /&gt;Input sub name $ bsl&lt;BR /&gt;Cards;&lt;BR /&gt;101 BT .&lt;BR /&gt;101 BT 36.8&lt;BR /&gt;101 BT .&lt;BR /&gt;101 BT .&lt;BR /&gt;101 BT .&lt;BR /&gt;101 RR .&lt;BR /&gt;101 RR 16&lt;BR /&gt;101 RR .&lt;BR /&gt;101 He 170&lt;BR /&gt;102 BT .&lt;BR /&gt;102 BT 33.4&lt;BR /&gt;102 BT .&lt;BR /&gt;102 BT .&lt;BR /&gt;102 BT .&lt;BR /&gt;102 He 160&lt;BR /&gt;102 RR .&lt;BR /&gt;102 RR . 16&lt;BR /&gt;102 RR .&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;So I Need to retain missing values with the existing value for each name(BT,RR).How to do that.could one&lt;BR /&gt;anyone please help me for this query..&lt;BR /&gt;&lt;BR /&gt;Thank you&lt;BR /&gt;&lt;BR /&gt;Regards..&lt;BR /&gt;</description>
      <pubDate>Mon, 02 Mar 2020 09:26:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-retain-the-values/m-p/628699#M185817</guid>
      <dc:creator>sasuser123123</dc:creator>
      <dc:date>2020-03-02T09:26:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to retain the values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-the-values/m-p/628700#M185818</link>
      <description>&lt;P&gt;So what does your desired result look like from this data?&lt;/P&gt;</description>
      <pubDate>Mon, 02 Mar 2020 09:27:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-retain-the-values/m-p/628700#M185818</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-03-02T09:27:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to retain the values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-the-values/m-p/628701#M185819</link>
      <description>Thank you for quick response..&lt;BR /&gt;&lt;BR /&gt;My output should be like..&lt;BR /&gt;&lt;BR /&gt;101 BT 36.8&lt;BR /&gt;101 BT 36.8&lt;BR /&gt;101 BT 36.8&lt;BR /&gt;101 BT 36.8&lt;BR /&gt;101 BT 36.8&lt;BR /&gt;101 RR 16&lt;BR /&gt;101 RR 16&lt;BR /&gt;101 RR 16&lt;BR /&gt;101 He 170&lt;BR /&gt;102 BT 33.4&lt;BR /&gt;102 BT 33.4&lt;BR /&gt;102 BT 33.4&lt;BR /&gt;102 BT 33.4&lt;BR /&gt;102 BT 33.4&lt;BR /&gt;102 He 160&lt;BR /&gt;102 RR 16&lt;BR /&gt;102 RR 16&lt;BR /&gt;102 RR 16&lt;BR /&gt;&lt;BR /&gt;Thank you!!&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 02 Mar 2020 09:30:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-retain-the-values/m-p/628701#M185819</guid>
      <dc:creator>sasuser123123</dc:creator>
      <dc:date>2020-03-02T09:30:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to retain the values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-the-values/m-p/628706#M185820</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/282134"&gt;@sasuser123123&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an approach, using a hash:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	if _n_=1 then do;
		declare hash h (dataset:'new (where=(bsl ne .))');
		h.definekey('sub','name');
		h.definedata('bsl');
		h.definedone();
	end;
	set new;
	if h.find()=0 then output;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Mar 2020 09:46:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-retain-the-values/m-p/628706#M185820</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-03-02T09:46:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to retain the values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-the-values/m-p/628707#M185821</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data new;
Input sub name $ bsl;
datalines;
101 BT .
101 BT 36.8
101 BT .
101 BT .
101 BT .
101 RR .
101 RR 16
101 RR .
101 He 170
102 BT .
102 BT 33.4
102 BT .
102 BT .
102 BT .
102 He 160
102 RR .
102 RR 16
102 RR .
;

data want(drop=_bsl);
    do _N_=1 by 1 until (last.sub | last.name);
        set new;
        by sub name notsorted;
        _bsl = max(bsl, _bsl);
    end;
    do _N_=1 to _N_;
        set new;
        bsl = _bsl;
        output;
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 02 Mar 2020 09:51:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-retain-the-values/m-p/628707#M185821</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-03-02T09:51:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to retain the values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-the-values/m-p/628708#M185822</link>
      <description>&lt;P&gt;Another approach could be:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=new out=new_sorted;
	by sub name descending bsl;
run;
data want;
	set new_sorted;
	retain bsl_new;
	if bsl ne . then bsl_new = bsl;
	drop bsl;
	rename bsl_new = bsl;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 02 Mar 2020 09:50:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-retain-the-values/m-p/628708#M185822</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-03-02T09:50:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to retain the values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-the-values/m-p/628713#M185825</link>
      <description>&lt;P&gt;What if you have more than one non-missing value per group, which one should take precedence?&lt;/P&gt;</description>
      <pubDate>Mon, 02 Mar 2020 10:20:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-retain-the-values/m-p/628713#M185825</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-03-02T10:20:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to retain the values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-the-values/m-p/628715#M185827</link>
      <description>It depends on condition that they would give...&lt;BR /&gt;&lt;BR /&gt;Like average or sum of that values&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 02 Mar 2020 10:33:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-retain-the-values/m-p/628715#M185827</guid>
      <dc:creator>sasuser123123</dc:creator>
      <dc:date>2020-03-02T10:33:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to retain the values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-the-values/m-p/628716#M185828</link>
      <description>&lt;P&gt;My code easily handles the different situations. For sum, run the code below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want(drop=_bsl);
    do _N_=1 by 1 until (last.sub | last.name);
        set new;
        by sub name notsorted;
        _bsl = sum(bsl, _bsl);
    end;
    do _N_=1 to _N_;
        set new;
        bsl = _bsl;
        output;
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 02 Mar 2020 10:36:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-retain-the-values/m-p/628716#M185828</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-03-02T10:36:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to retain the values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-the-values/m-p/628719#M185829</link>
      <description>Hello &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt; I just used your code and got desired values wherever multiple observations per name , but got missing value for 'He'. record&lt;BR /&gt;&lt;BR /&gt;And also why did we used max or sum function&lt;BR /&gt;&lt;BR /&gt;I didn't get your code.. could you please explain it in short .&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Thank you</description>
      <pubDate>Mon, 02 Mar 2020 10:40:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-retain-the-values/m-p/628719#M185829</guid>
      <dc:creator>sasuser123123</dc:creator>
      <dc:date>2020-03-02T10:40:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to retain the values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-the-values/m-p/628724#M185832</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/282134"&gt;@sasuser123123&lt;/a&gt;&amp;nbsp;glad you found your answer &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) My code returns a non-mising value fir the 'He' record when you run the code below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) Shortly put, the code is structured as follows. I read the data twice, one By-Group at the time using a &lt;A href="http://support.sas.com/resources/papers/proceedings09/038-2009.pdf" target="_self"&gt;Double DoW Loop&lt;/A&gt;. For each By-Group, I use the Sum Function to calculate the sum of the bsl variable. This will give me the sum of bsl for the entire group. Next, I read the same By-Group in the second DoW loop and assign the sum of bsl (_bsl) to each value of bsl and then output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope it makes more sense now. Otherwise, don't hesitate to ask &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data new;
Input sub name $ bsl;
datalines;
101 BT .
101 BT 36.8
101 BT .
101 BT .
101 BT .
101 RR .
101 RR 16
101 RR .
101 He 170
102 BT .
102 BT 33.4
102 BT .
102 BT .
102 BT .
102 He 160
102 RR .
102 RR 16
102 RR .
;

data want(drop=_bsl);
    do _N_=1 by 1 until (last.sub | last.name);
        set new;
        by sub name notsorted;
        _bsl = max(bsl, _bsl);
    end;
    do _N_=1 to _N_;
        set new;
        bsl = _bsl;
        output;
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;sub  name bsl 
101  BT    36.8 
101  BT    36.8 
101  BT    36.8 
101  BT    36.8 
101  BT    36.8 
101  RR    16.0 
101  RR    16.0 
101  RR    16.0 
101  He    170.0 
102  BT    33.4 
102  BT    33.4 
102  BT    33.4 
102  BT    33.4 
102  BT    33.4 
102  He    160.0 
102  RR    16.0 
102  RR    16.0 
102  RR    16.0 
&lt;/PRE&gt;</description>
      <pubDate>Mon, 02 Mar 2020 10:56:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-retain-the-values/m-p/628724#M185832</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-03-02T10:56:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to retain the values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-the-values/m-p/628779#M185862</link>
      <description>Thank you so much for your assistance</description>
      <pubDate>Mon, 02 Mar 2020 14:45:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-retain-the-values/m-p/628779#M185862</guid>
      <dc:creator>sasuser123123</dc:creator>
      <dc:date>2020-03-02T14:45:04Z</dc:date>
    </item>
  </channel>
</rss>

