<?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: i have a data from which i need average for 101 and 102 and a flag populated for average values. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/i-have-a-data-from-which-i-need-average-for-101-and-102-and-a/m-p/515617#M139158</link>
    <description>&lt;P&gt;I purposely didn't write the condition although gave you the exquisite corrections &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp; for both your steps&lt;/P&gt;
&lt;P&gt;hint:use in= for your condition&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PLus your sql is not perfect either requires some correction/modification&lt;/P&gt;</description>
    <pubDate>Fri, 23 Nov 2018 17:07:18 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2018-11-23T17:07:18Z</dc:date>
    <item>
      <title>i have a data from which i need average for 101 and 102 and a flag populated for average values.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/i-have-a-data-from-which-i-need-average-for-101-and-102-and-a/m-p/515559#M139121</link>
      <description>&lt;P&gt;data vs;&lt;/P&gt;&lt;P&gt;input pt&amp;nbsp; test$&amp;nbsp; result;&lt;/P&gt;&lt;P&gt;cards;&lt;BR /&gt;101 SBP 150&lt;BR /&gt;101 SBP 152&lt;BR /&gt;102 DBP 48&lt;BR /&gt;102 DBP 52&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Nov 2018 14:33:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/i-have-a-data-from-which-i-need-average-for-101-and-102-and-a/m-p/515559#M139121</guid>
      <dc:creator>Aliya-begum</dc:creator>
      <dc:date>2018-11-23T14:33:10Z</dc:date>
    </item>
    <item>
      <title>Re: i have a data from which i need average for 101 and 102 and a flag populated for average values.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/i-have-a-data-from-which-i-need-average-for-101-and-102-and-a/m-p/515561#M139123</link>
      <description>&lt;P&gt;You need to be clearer in your post.&amp;nbsp; Show what you want out for instance.&amp;nbsp; I can guess that proc means will give you the average:&lt;/P&gt;
&lt;PRE&gt;proc means data=vs;
  class pt;
  var result;
  output out=want mean=mean;
run;&lt;/PRE&gt;
&lt;P&gt;But I don't know about flags as there is not average in that data, nor would the output from above be in your data to flag??&lt;/P&gt;</description>
      <pubDate>Fri, 23 Nov 2018 14:37:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/i-have-a-data-from-which-i-need-average-for-101-and-102-and-a/m-p/515561#M139123</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-11-23T14:37:22Z</dc:date>
    </item>
    <item>
      <title>Re: i have a data from which i need average for 101 and 102 and a flag populated for average values.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/i-have-a-data-from-which-i-need-average-for-101-and-102-and-a/m-p/515562#M139124</link>
      <description>&lt;P&gt;The average can be done quite simply in SQL:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select pt, test, avg(result) as result_avg
from vs
group by pt, test;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What value should end up in the "flag"?&lt;/P&gt;</description>
      <pubDate>Fri, 23 Nov 2018 14:38:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/i-have-a-data-from-which-i-need-average-for-101-and-102-and-a/m-p/515562#M139124</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-11-23T14:38:51Z</dc:date>
    </item>
    <item>
      <title>Re: i have a data from which i need average for 101 and 102 and a flag populated for average values.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/i-have-a-data-from-which-i-need-average-for-101-and-102-and-a/m-p/515572#M139130</link>
      <description>As i have the data&lt;BR /&gt;&lt;BR /&gt;data vs;&lt;BR /&gt;input pt test$ result;&lt;BR /&gt;cards;&lt;BR /&gt;101 SBP 150&lt;BR /&gt;101 SBP 152&lt;BR /&gt;102 DBP 48&lt;BR /&gt;102 DBP 52&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;i need an output as given below&lt;BR /&gt;&lt;BR /&gt;pt test result res_avg flag&lt;BR /&gt;101 SBP 150 150&lt;BR /&gt;101 SBP 152 152&lt;BR /&gt;101 SBP 151 y&lt;BR /&gt;&lt;BR /&gt;102 DBP 48 48&lt;BR /&gt;102 DBP 52 52&lt;BR /&gt;102 DBP 50 y&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 23 Nov 2018 15:14:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/i-have-a-data-from-which-i-need-average-for-101-and-102-and-a/m-p/515572#M139130</guid>
      <dc:creator>Aliya-begum</dc:creator>
      <dc:date>2018-11-23T15:14:39Z</dc:date>
    </item>
    <item>
      <title>I have a data set with three variables i need average of result varible and flag for average values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/i-have-a-data-from-which-i-need-average-for-101-and-102-and-a/m-p/515580#M139136</link>
      <description>&lt;P&gt;data vs;&lt;BR /&gt;input pt test$ @15 result;&lt;BR /&gt;cards;&lt;BR /&gt;101 SBP 150&lt;BR /&gt;101 SBP 152&lt;BR /&gt;102 DBP 48&lt;BR /&gt;102 DBP 52&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;proc print;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i need output as given below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; pt&amp;nbsp; &amp;nbsp; &amp;nbsp;test&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; result&amp;nbsp; &amp;nbsp; &amp;nbsp;res_avg&amp;nbsp; &amp;nbsp; flag&lt;BR /&gt;&lt;BR /&gt;101&amp;nbsp; &amp;nbsp;SBP&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 150&amp;nbsp; &amp;nbsp; &amp;nbsp; 150&lt;BR /&gt;101&amp;nbsp; &amp;nbsp;SBP&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 152&amp;nbsp; &amp;nbsp; &amp;nbsp; 152&lt;BR /&gt;101&amp;nbsp; &amp;nbsp;SBP&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 151&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;y&lt;BR /&gt;&lt;BR /&gt;102&amp;nbsp; &amp;nbsp;DBP&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 48&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 48&lt;BR /&gt;102&amp;nbsp; &amp;nbsp;DBP&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 52&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 52&lt;BR /&gt;102&amp;nbsp; &amp;nbsp;DBP&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 50&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;y&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Nov 2018 15:36:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/i-have-a-data-from-which-i-need-average-for-101-and-102-and-a/m-p/515580#M139136</guid>
      <dc:creator>Aliya-begum</dc:creator>
      <dc:date>2018-11-23T15:36:35Z</dc:date>
    </item>
    <item>
      <title>Re: i have a data from which i need average for 101 and 102 and a flag populated for average values.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/i-have-a-data-from-which-i-need-average-for-101-and-102-and-a/m-p/515582#M139134</link>
      <description>&lt;P&gt;Right, so do the means step, then set that with your data e.g.&lt;/P&gt;
&lt;PRE&gt;proc means data=vs;
  class pt;
  var result;
  output out=want mean=mean;
run;

data vs;
  set vs (in=a) mean (in=b);
  if b then flag="Y";
run;
&lt;/PRE&gt;</description>
      <pubDate>Fri, 23 Nov 2018 15:41:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/i-have-a-data-from-which-i-need-average-for-101-and-102-and-a/m-p/515582#M139134</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-11-23T15:41:00Z</dc:date>
    </item>
    <item>
      <title>Re: I have a data set with three variables i need average of result varible and flag for average val</title>
      <link>https://communities.sas.com/t5/SAS-Programming/i-have-a-data-from-which-i-need-average-for-101-and-102-and-a/m-p/515587#M139138</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data vs;
input pt test$  result;
cards;
101 SBP 150
101 SBP 152
102 DBP 48
102 DBP 52
;

data want;
s=0;
do _n_=1 by 1 until(last.pt);
set vs;
by pt;
res_avg=result;
s+result;
output;
end;
result=.;
res_avg=s/_n_;
flag='Y';
output;
drop s;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 23 Nov 2018 15:52:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/i-have-a-data-from-which-i-need-average-for-101-and-102-and-a/m-p/515587#M139138</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-11-23T15:52:53Z</dc:date>
    </item>
    <item>
      <title>Re: i have a data from which i need average for 101 and 102 and a flag populated for average values.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/i-have-a-data-from-which-i-need-average-for-101-and-102-and-a/m-p/515592#M139139</link>
      <description>&lt;P&gt;something like below may work&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data prefinal (drop = tot count);
do until(last.pt);
set vs;by pt;
tot= sum(tot, result);
count=sum(count,1);
avg=tot/count;
flag = 'Y';
end;
result = .;
run;

data want;
set vs prefinal;&lt;BR /&gt;by pt;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;you can also proc sql as&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select pt, test, result, . as avg, ' ' as flag from vs
union
select distinct  pt, test, . as result, mean(result) as avg, "Y" as flag
from vs
group by pt;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Nov 2018 16:59:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/i-have-a-data-from-which-i-need-average-for-101-and-102-and-a/m-p/515592#M139139</guid>
      <dc:creator>kiranv_</dc:creator>
      <dc:date>2018-11-23T16:59:50Z</dc:date>
    </item>
    <item>
      <title>Re: I have a data set with three variables i need average of result varible and flag for average val</title>
      <link>https://communities.sas.com/t5/SAS-Programming/i-have-a-data-from-which-i-need-average-for-101-and-102-and-a/m-p/515597#M139143</link>
      <description>&lt;P&gt;&lt;BR /&gt;proc means data=sashelp.class ;&lt;BR /&gt; class sex ;&lt;BR /&gt; var height;&lt;BR /&gt; output out=want mean=mean;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data vs;&lt;BR /&gt; set want (in=a) sashelp.class (in=b);&lt;BR /&gt; if sex not in ("");&lt;BR /&gt; if a then flag="Average";&lt;BR /&gt; if flag not in ("Average") then do; res_avg=height; end;&lt;BR /&gt;run;&lt;BR /&gt;proc sort data=vs; &lt;BR /&gt;by sex; run;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Nov 2018 16:28:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/i-have-a-data-from-which-i-need-average-for-101-and-102-and-a/m-p/515597#M139143</guid>
      <dc:creator>saslove</dc:creator>
      <dc:date>2018-11-23T16:28:59Z</dc:date>
    </item>
    <item>
      <title>Re: i have a data from which i need average for 101 and 102 and a flag populated for average values.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/i-have-a-data-from-which-i-need-average-for-101-and-102-and-a/m-p/515599#M139145</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/37783"&gt;@kiranv_&lt;/a&gt;&amp;nbsp; Your datastep&amp;nbsp; logic will not work if there are more than 2 records for each id and I believe that's kind of case in business is not likely&lt;/P&gt;</description>
      <pubDate>Fri, 23 Nov 2018 16:32:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/i-have-a-data-from-which-i-need-average-for-101-and-102-and-a/m-p/515599#M139145</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-11-23T16:32:53Z</dc:date>
    </item>
    <item>
      <title>Re: i have a data from which i need average for 101 and 102 and a flag populated for average values.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/i-have-a-data-from-which-i-need-average-for-101-and-102-and-a/m-p/515605#M139149</link>
      <description>&lt;P&gt;you are right and thanks for correcting me. I have updated my answer&lt;/P&gt;</description>
      <pubDate>Fri, 23 Nov 2018 16:43:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/i-have-a-data-from-which-i-need-average-for-101-and-102-and-a/m-p/515605#M139149</guid>
      <dc:creator>kiranv_</dc:creator>
      <dc:date>2018-11-23T16:43:41Z</dc:date>
    </item>
    <item>
      <title>Re: i have a data from which i need average for 101 and 102 and a flag populated for average values.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/i-have-a-data-from-which-i-need-average-for-101-and-102-and-a/m-p/515615#M139156</link>
      <description>&lt;P&gt;&amp;nbsp;Still you need to change your append to rather interleave and conditionally assign avg&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want1;
set vs prefinal;
by pt;
/*write the condition here*/
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 23 Nov 2018 16:57:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/i-have-a-data-from-which-i-need-average-for-101-and-102-and-a/m-p/515615#M139156</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-11-23T16:57:46Z</dc:date>
    </item>
    <item>
      <title>Re: i have a data from which i need average for 101 and 102 and a flag populated for average values.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/i-have-a-data-from-which-i-need-average-for-101-and-102-and-a/m-p/515616#M139157</link>
      <description>&lt;P&gt;you are right again. awesome points&lt;/P&gt;</description>
      <pubDate>Fri, 23 Nov 2018 16:59:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/i-have-a-data-from-which-i-need-average-for-101-and-102-and-a/m-p/515616#M139157</guid>
      <dc:creator>kiranv_</dc:creator>
      <dc:date>2018-11-23T16:59:15Z</dc:date>
    </item>
    <item>
      <title>Re: i have a data from which i need average for 101 and 102 and a flag populated for average values.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/i-have-a-data-from-which-i-need-average-for-101-and-102-and-a/m-p/515617#M139158</link>
      <description>&lt;P&gt;I purposely didn't write the condition although gave you the exquisite corrections &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp; for both your steps&lt;/P&gt;
&lt;P&gt;hint:use in= for your condition&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PLus your sql is not perfect either requires some correction/modification&lt;/P&gt;</description>
      <pubDate>Fri, 23 Nov 2018 17:07:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/i-have-a-data-from-which-i-need-average-for-101-and-102-and-a/m-p/515617#M139158</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-11-23T17:07:18Z</dc:date>
    </item>
    <item>
      <title>Re: i have a data from which i need average for 101 and 102 and a flag populated for average values.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/i-have-a-data-from-which-i-need-average-for-101-and-102-and-a/m-p/515718#M139197</link>
      <description>&lt;P&gt;This is a long thread, and I am jumping in late, but I highly recommend the solution by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;. You want to use PROC MEANS or PROC SUMMARY to do the computation of statistics across groups, that is one of the features of PROC MEANS/PROC SUMMARY, plus it handles missing values properly, plus it has been tested, debugged and validated in a bazillion, 408 thousand and three real-world applications.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;You do not want to write your own data step code to compute group means&lt;/STRONG&gt;. Not only is this unnecessarily time consuming to write and test this code compared to using the features in PROC MEANS/PROC SUMMARY, but writing your own code also runs the risk of bugs and incorrect answers (which is not the case with using PROC MEANS/PROC SUMMARY).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Right, so do the means step, then set that with your data e.g.&lt;/P&gt;
&lt;PRE&gt;proc means data=vs;
  class pt;
  var result;
  output out=want mean=mean;
run;

data vs;
  set vs (in=a) mean (in=b);
  if b then flag="Y";
run;
&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 24 Nov 2018 14:14:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/i-have-a-data-from-which-i-need-average-for-101-and-102-and-a/m-p/515718#M139197</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-11-24T14:14:13Z</dc:date>
    </item>
  </channel>
</rss>

