<?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 values based on by variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Replace-missing-values-based-on-by-variable/m-p/679190#M205088</link>
    <description>Why 'on' condition only in PE variable?&lt;BR /&gt;&lt;BR /&gt;I have apply the same logic  in PE like how I need for RC, AA and CO?&lt;BR /&gt;</description>
    <pubDate>Tue, 25 Aug 2020 15:53:21 GMT</pubDate>
    <dc:creator>David_Billa</dc:creator>
    <dc:date>2020-08-25T15:53:21Z</dc:date>
    <item>
      <title>Replace missing values based on by variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-missing-values-based-on-by-variable/m-p/679167#M205076</link>
      <description>&lt;P&gt;I've the data as below.Now I want to replace missing values from the variables (PE,CR,AA and CO)&amp;nbsp;with the the value of the&amp;nbsp;respective variable based on by variable(Code) . Any help?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Code	PE	CR	AA	CO
AS3	0.1285	2.152	.	.
AS3	0.1285	.	.	.
AS3	0.1285	.	.	.
AS3	0.1285	2.152	.	.
AS3	0.1285	.	0.0342	0.0331
AS3	0.1285	.	0.0342	0.0331
AS3	0.1285	2.152	.	.
AS4	0.1329	2.013	0.0326	0.0324
AS4	0.1329	.	0.0326	0.0324
AS4	0.1329	.	0.0326	0.0324
&lt;/PRE&gt;
&lt;P&gt;Desired result is,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Code	PE	CR	AA	CO
AS3	0.1285	2.152	0.0342	0.0331
AS3	0.1285	2.152	0.0342	0.0331
AS3	0.1285	2.152	0.0342	0.0331
AS3	0.1285	2.152	0.0342	0.0331
AS3	0.1285	2.152	0.0342	0.0331
AS3	0.1285	2.152	0.0342	0.0331
AS3	0.1285	2.152	0.0342	0.0331
AS4	0.1329	2.013	0.0326	0.0324
AS4	0.1329	2.013	0.0326	0.0324
AS4	0.1329	2.013	0.0326	0.0324
&lt;/PRE&gt;</description>
      <pubDate>Tue, 25 Aug 2020 14:45:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-missing-values-based-on-by-variable/m-p/679167#M205076</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2020-08-25T14:45:03Z</dc:date>
    </item>
    <item>
      <title>Re: Replace missing values based on by variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-missing-values-based-on-by-variable/m-p/679169#M205077</link>
      <description>&lt;P&gt;These variables always have the exact same value on &lt;EM&gt;every observation&lt;/EM&gt; of the BY variable CODE? And they change only when CODE changes? you can use PROC STDIZE with the REPONLY option and METHOD=MEAN.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Aug 2020 14:53:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-missing-values-based-on-by-variable/m-p/679169#M205077</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-08-25T14:53:46Z</dc:date>
    </item>
    <item>
      <title>Re: Replace missing values based on by variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-missing-values-based-on-by-variable/m-p/679171#M205079</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input Code $	PE	CR	AA	CO;
cards;
AS3	0.1285	2.152	.	.
AS3	0.1285	.	.	.
AS3	0.1285	.	.	.
AS3	0.1285	2.152	.	.
AS3	0.1285	.	0.0342	0.0331
AS3	0.1285	.	0.0342	0.0331
AS3	0.1285	2.152	.	.
AS4	0.1329	2.013	0.0326	0.0324
AS4	0.1329	.	0.0326	0.0324
AS4	0.1329	.	0.0326	0.0324
;
proc means data=have nway noprint;
 class code pe;
 var cr--co;
 output out=temp(drop=_:) max=;
run;

data want;
 merge  have(keep=code pe) temp;
 by code pe;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 25 Aug 2020 14:54:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-missing-values-based-on-by-variable/m-p/679171#M205079</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-08-25T14:54:44Z</dc:date>
    </item>
    <item>
      <title>Re: Replace missing values based on by variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-missing-values-based-on-by-variable/m-p/679173#M205080</link>
      <description>&lt;P&gt;SQL-&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input Code $	PE	CR	AA	CO;
cards;
AS3	0.1285	2.152	.	.
AS3	0.1285	.	.	.
AS3	0.1285	.	.	.
AS3	0.1285	2.152	.	.
AS3	0.1285	.	0.0342	0.0331
AS3	0.1285	.	0.0342	0.0331
AS3	0.1285	2.152	.	.
AS4	0.1329	2.013	0.0326	0.0324
AS4	0.1329	.	0.0326	0.0324
AS4	0.1329	.	0.0326	0.0324
;

proc sql;
 create table want as
 select b.*
 from (select code,pe from have) a
 left join
 (select code ,pe,max(cr) as cr, max(aa) as aa,max(co) as co
 from have
 group by code,pe) b
 on a.code=b.code and a.pe=b.pe;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 25 Aug 2020 15:00:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-missing-values-based-on-by-variable/m-p/679173#M205080</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-08-25T15:00:08Z</dc:date>
    </item>
    <item>
      <title>Re: Replace missing values based on by variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-missing-values-based-on-by-variable/m-p/679174#M205081</link>
      <description>&lt;P&gt;What if you have more than one different value for a variable within a group? Should that result in a program ERROR, or should a specific value take precedence?&lt;/P&gt;</description>
      <pubDate>Tue, 25 Aug 2020 15:01:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-missing-values-based-on-by-variable/m-p/679174#M205081</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-08-25T15:01:28Z</dc:date>
    </item>
    <item>
      <title>Re: Replace missing values based on by variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-missing-values-based-on-by-variable/m-p/679177#M205082</link>
      <description>There will not be more than one different value within a same group.&lt;BR /&gt;&lt;BR /&gt;Example I posted resembles the real life data&lt;BR /&gt;</description>
      <pubDate>Tue, 25 Aug 2020 15:11:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-missing-values-based-on-by-variable/m-p/679177#M205082</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2020-08-25T15:11:21Z</dc:date>
    </item>
    <item>
      <title>Re: Replace missing values based on by variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-missing-values-based-on-by-variable/m-p/679178#M205083</link>
      <description>There will not be more than one different value within a same group.&lt;BR /&gt;</description>
      <pubDate>Tue, 25 Aug 2020 15:11:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-missing-values-based-on-by-variable/m-p/679178#M205083</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2020-08-25T15:11:23Z</dc:date>
    </item>
    <item>
      <title>Re: Replace missing values based on by variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-missing-values-based-on-by-variable/m-p/679179#M205084</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;There will not be more than one different value within a same group.&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Then you can use PROC STDIZE as I described.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Aug 2020 15:12:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-missing-values-based-on-by-variable/m-p/679179#M205084</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-08-25T15:12:42Z</dc:date>
    </item>
    <item>
      <title>Re: Replace missing values based on by variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-missing-values-based-on-by-variable/m-p/679186#M205087</link>
      <description>&lt;P&gt;As&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;said use PROC STDIZE.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input Code $ PE  CR  AA  CO;
cards;
AS3  0.1285  2.152  .  .
AS3  0.1285  .  .  .
AS3  0.1285  .  .  .
AS3  0.1285  2.152  .  .
AS3  0.1285  .  0.0342  0.0331
AS3  0.1285  .  0.0342  0.0331
AS3  0.1285  2.152  .  .
AS4  0.1329  2.013  0.0326  0.0324
AS4  0.1329  .  0.0326  0.0324
AS4  0.1329  .  0.0326  0.0324
;

proc stdize data=have out=want REPONLY METHOD=MEAN;
  by code;
  var pe cr aa co;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could also try this trick using WHERE clauses on different cuts of the data.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want2;
  merge have (drop=pe cr aa co)
        have (keep=code pe where=(not missing(pe)))
        have (keep=code cr where=(not missing(cr)))
        have (keep=code aa where=(not missing(aa)))
        have (keep=code co where=(not missing(co)))
  ;
  by code;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 25 Aug 2020 15:30:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-missing-values-based-on-by-variable/m-p/679186#M205087</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-08-25T15:30:48Z</dc:date>
    </item>
    <item>
      <title>Re: Replace missing values based on by variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-missing-values-based-on-by-variable/m-p/679190#M205088</link>
      <description>Why 'on' condition only in PE variable?&lt;BR /&gt;&lt;BR /&gt;I have apply the same logic  in PE like how I need for RC, AA and CO?&lt;BR /&gt;</description>
      <pubDate>Tue, 25 Aug 2020 15:53:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-missing-values-based-on-by-variable/m-p/679190#M205088</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2020-08-25T15:53:21Z</dc:date>
    </item>
    <item>
      <title>Re: Replace missing values based on by variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-missing-values-based-on-by-variable/m-p/679191#M205089</link>
      <description>&lt;P&gt;Do you expect PE variable also to have missing values like&amp;nbsp;&lt;SPAN&gt;RC, AA and CO?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Oh well, I assumed &lt;STRONG&gt;CODE PE&lt;/STRONG&gt; values as unique combination forming a&amp;nbsp;&lt;STRONG&gt;BY group.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Okay, Please try the below-&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
 create table want as
 select b.*
 from (select code from have) a
 left join
 (select code ,max(pe) as pe,max(cr) as cr, max(aa) as aa,max(co) as co
 from have
 group by code) b
 on a.code=b.code ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 25 Aug 2020 15:57:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-missing-values-based-on-by-variable/m-p/679191#M205089</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-08-25T15:57:12Z</dc:date>
    </item>
    <item>
      <title>Re: Replace missing values based on by variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-missing-values-based-on-by-variable/m-p/679203#M205095</link>
      <description>&lt;P&gt;PROC STDIZE does them all at once in one step and is less code than any other approach.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Aug 2020 16:52:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-missing-values-based-on-by-variable/m-p/679203#M205095</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-08-25T16:52:56Z</dc:date>
    </item>
  </channel>
</rss>

