<?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: PROC MEANS, how to identify the observations that belong to one row in the output table in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROC-MEANS-how-to-identify-the-observations-that-belong-to-one/m-p/515479#M139083</link>
    <description>Are you just looking for the number of observations used in the calculation of the statistics? If so, the N statistic will do that. Unlike other procs, Proc Means does not exclude row wise, it excludes per variable.</description>
    <pubDate>Fri, 23 Nov 2018 04:54:44 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2018-11-23T04:54:44Z</dc:date>
    <item>
      <title>PROC MEANS, how to identify the observations that belong to one row in the output table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-MEANS-how-to-identify-the-observations-that-belong-to-one/m-p/515457#M139076</link>
      <description>&lt;P&gt;The moment I subset the output of proc means things get complicated.&lt;/P&gt;
&lt;P&gt;For the where clause I don't have all the obs from the input data set.&lt;/P&gt;
&lt;P&gt;I haven't found any ods table that outputs the "real" used observations, like it is possible with proc sgplot for example.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;From the output table I could build a filter with "proc sql select into :" to subset my in-data set, but it's a lot of work.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Therefore the best option I found for the moment is to cycle through different num variables in the data set and use them in conjunction with ID variable and maxid and minid. this way I get at least 2 IDs for any row of the proc means output.&lt;/P&gt;
&lt;P&gt;Doing this over an over brings me closer to the real amount of obs used.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I have few obs per row in proc means output, it's ok, but for large numbers I must write a macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA CARS;
SET SASHELP.CARS;
OBS_ID=_N_;
RUN;


%LET CH=Invoice;
PROC MEANS DATA=WORK.CARS NOPRINT ;
CLASS Make DriveTrain ;
VAR  MSRP;
ID  OBS_ID;
OUTPUT OUT=PROM(WHERE=(_TYPE_ = 3 AND _FREQ_ GT 10))
MEDIAN=MED MEAN=MEAN  MINID(&amp;amp;CH)=MIN_ID MAXID(&amp;amp;CH)=MAX_ID /  LEVELS;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="proc means.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/25134iEAB29361ADC1388F/image-size/large?v=v2&amp;amp;px=999" role="button" title="proc means.png" alt="proc means.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Nov 2018 23:12:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-MEANS-how-to-identify-the-observations-that-belong-to-one/m-p/515457#M139076</guid>
      <dc:creator>acordes</dc:creator>
      <dc:date>2018-11-22T23:12:09Z</dc:date>
    </item>
    <item>
      <title>Re: PROC MEANS, how to identify the observations that belong to one row in the output table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-MEANS-how-to-identify-the-observations-that-belong-to-one/m-p/515459#M139078</link>
      <description>&lt;P&gt;It’s not clear what you have and what you want from this post. Can you include an example of what you have or what you would want as output using sashelp.cars perhaps?&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/127222"&gt;@acordes&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;The moment I subset the output of proc means things get complicated.&lt;/P&gt;
&lt;P&gt;For the where clause I don't have all the obs from the input data set.&lt;/P&gt;
&lt;P&gt;I haven't found any ods table that outputs the "real" used observations, like it is possible with proc sgplot for example.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;From the output table I could build a filter with "proc sql select into :" to subset my in-data set, but it's a lot of work.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Therefore the best option I found for the moment is to cycle through different num variables in the data set and use them in conjunction with ID variable and maxid and minid. this way I get at least 2 IDs for any row of the proc means output.&lt;/P&gt;
&lt;P&gt;Doing this over an over brings me closer to the real amount of obs used.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I have few obs per row in proc means output, it's ok, but for large numbers I must write a macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA CARS;
SET SASHELP.CARS;
OBS_ID=_N_;
RUN;


%LET CH=Invoice;
PROC MEANS DATA=WORK.CARS NOPRINT ;
CLASS Make DriveTrain ;
VAR  MSRP;
ID  OBS_ID;
OUTPUT OUT=PROM(WHERE=(_TYPE_ = 3 AND _FREQ_ GT 10))
MEDIAN=MED MEAN=MEAN  MINID(&amp;amp;CH)=MIN_ID MAXID(&amp;amp;CH)=MAX_ID /  LEVELS;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="proc means.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/25134iEAB29361ADC1388F/image-size/large?v=v2&amp;amp;px=999" role="button" title="proc means.png" alt="proc means.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Nov 2018 23:36:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-MEANS-how-to-identify-the-observations-that-belong-to-one/m-p/515459#M139078</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-11-22T23:36:47Z</dc:date>
    </item>
    <item>
      <title>Re: PROC MEANS, how to identify the observations that belong to one row in the output table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-MEANS-how-to-identify-the-observations-that-belong-to-one/m-p/515476#M139082</link>
      <description>&lt;P&gt;If what you want is to select high frequency classes, you could use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC MEANS DATA=SASHELP.CARS NOPRINT NWAY;
CLASS Make DriveTrain ;
VAR  MSRP;
OUTPUT OUT=PROM MEDIAN=MED MEAN=MEAN;
RUN;

proc sql;
create table popularMakes as
select a.*, b.mean, b.med  
from 
    sashelp.cars as a inner join
    prom as b on a.make=b.make and a.DriveTrain=b.DriveTrain
where b._freq_ &amp;gt; 10;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 23 Nov 2018 04:43:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-MEANS-how-to-identify-the-observations-that-belong-to-one/m-p/515476#M139082</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-11-23T04:43:40Z</dc:date>
    </item>
    <item>
      <title>Re: PROC MEANS, how to identify the observations that belong to one row in the output table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-MEANS-how-to-identify-the-observations-that-belong-to-one/m-p/515479#M139083</link>
      <description>Are you just looking for the number of observations used in the calculation of the statistics? If so, the N statistic will do that. Unlike other procs, Proc Means does not exclude row wise, it excludes per variable.</description>
      <pubDate>Fri, 23 Nov 2018 04:54:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-MEANS-how-to-identify-the-observations-that-belong-to-one/m-p/515479#M139083</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-11-23T04:54:44Z</dc:date>
    </item>
    <item>
      <title>Re: PROC MEANS, how to identify the observations that belong to one row in the output table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-MEANS-how-to-identify-the-observations-that-belong-to-one/m-p/515490#M139086</link>
      <description>&lt;P&gt;Thanks to all for the responses.&lt;/P&gt;
&lt;P&gt;It's my fault to not have explained well what I want.&lt;/P&gt;
&lt;P&gt;Let's suppose that I read 100 observations into PROC Means. I use several class variables which will lead to different _type_ analysis in the output. I.e. without using nway&amp;nbsp;option or restricting the _type_, the 0 level will have the statistics for all 100 variables.&lt;/P&gt;
&lt;P&gt;Imagine that I am only interested in the _type_=4 which could be the the Crossing of Make and Gear Box and in its line might apper&amp;nbsp;the statistics for 23 members that fall into this group.&lt;/P&gt;
&lt;P&gt;I want to unveil the members of the group, which 23 observations participated in the row statistics.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Something similar to the option in proc sgplot:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class="text"&gt;proc sgplot noautolegend nocycleattrs;
   ods output sgplot=sg;&lt;/PRE&gt;</description>
      <pubDate>Fri, 23 Nov 2018 06:15:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-MEANS-how-to-identify-the-observations-that-belong-to-one/m-p/515490#M139086</guid>
      <dc:creator>acordes</dc:creator>
      <dc:date>2018-11-23T06:15:11Z</dc:date>
    </item>
    <item>
      <title>Re: PROC MEANS, how to identify the observations that belong to one row in the output table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-MEANS-how-to-identify-the-observations-that-belong-to-one/m-p/515513#M139096</link>
      <description>&lt;P&gt;Thanks, but I am not interested in the high frequency ones.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As I subset the output data set by selecting only a specific _type_ that furthermore meets a conditon (here that median and mean are equal, for me it serves as a control for the quality of the want data set), I lose track of the observations with its ID that finally underpin the output statistics.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to know every member of each row of the output data set.&lt;/P&gt;
&lt;P&gt;For sure I could buid a where filter clause that selects only these observations from the incoming data set, but this seems suboptimal to me as it envolves a lot of work.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Nov 2018 09:56:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-MEANS-how-to-identify-the-observations-that-belong-to-one/m-p/515513#M139096</guid>
      <dc:creator>acordes</dc:creator>
      <dc:date>2018-11-23T09:56:17Z</dc:date>
    </item>
    <item>
      <title>Re: PROC MEANS, how to identify the observations that belong to one row in the output table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-MEANS-how-to-identify-the-observations-that-belong-to-one/m-p/515535#M139108</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/127222"&gt;@acordes&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Maybe you can use PROC SQL instead of PROC MEANS:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Create test data */

data have;
call streaminit(27182818);
call stream(268);
id=5;
do make='A', 'B', 'C';
  do gearbox=3,2,1;
    do _n_=1 to rand('integer',23);
      id=mod(67*id, 101);
      cyl=4*rand('table',.25,.5,.25);
      output;
    end;
  end;
end;
run; /* 100 obs. */

/* Instead of PROC MEANS ...

proc means data=have n mean median;
class make gearbox;
var cyl;
output out=stats(where=(_type_=3 &amp;amp; mean_cyl=median_cyl)) mean=mean_cyl median=median_cyl;
run;

... use PROC SQL: */

proc sql;
create table want as
select make, gearbox, n(cyl) as n, mean(cyl) as mean_cyl, median(cyl) as median_cyl, id
from have
group by make, gearbox
having mean_cyl=median_cyl
order by 1,2,6;
quit;

proc print data=want;
by make gearbox n me:;
id id;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Dataset STATS would only show the summary statistics for the selected CLASS levels:&lt;/P&gt;
&lt;PRE&gt;                                                   median_
make    gearbox    _TYPE_    _FREQ_    mean_cyl      cyl

 A         1          3        23          8           8
 A         3          3         6         10          10
 B         3          3         4          8           8
 C         2          3         5          8           8&lt;/PRE&gt;
&lt;P&gt;PROC SQL, however, yields both summary statistics and individual ID values (thanks to remerging).&lt;/P&gt;
&lt;P&gt;Partial PROC PRINT output (dataset WANT):&lt;/P&gt;
&lt;PRE&gt;make=A gearbox=1 n=23 mean_cyl=8 median_cyl=8

 id

  3
  4
 17
 20
 21
 27
 28
 34
 36
 38
 39
 41
 48
 56
 58
 66
 79
 85
 88
 89
 92
 94
100


make=A gearbox=3 n=6 mean_cyl=10 median_cyl=10

id

14
23
25
26
32
59

(...)&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/127222"&gt;@acordes&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Imagine that I am only interested in the _type_=4 which could be the the Crossing of Make and Gear Box and in its line might apper&amp;nbsp;the statistics for 23 members that fall into this group.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;No, _type_=4 (=power of 2) represents always values of a&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;single&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;CLASS variable.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Nov 2018 13:01:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-MEANS-how-to-identify-the-observations-that-belong-to-one/m-p/515535#M139108</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2018-11-23T13:01:05Z</dc:date>
    </item>
    <item>
      <title>Re: PROC MEANS, how to identify the observations that belong to one row in the output table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-MEANS-how-to-identify-the-observations-that-belong-to-one/m-p/531456#M145455</link>
      <description>@freelancereinhard super elegant solution.&lt;BR /&gt;I take notice of all the nice techniques you used. The only thing I don't understand is in regard to the data step. how do you control to get 100 obs and how do you ensure that no ID gets duplicated?</description>
      <pubDate>Wed, 30 Jan 2019 18:19:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-MEANS-how-to-identify-the-observations-that-belong-to-one/m-p/531456#M145455</guid>
      <dc:creator>acordes</dc:creator>
      <dc:date>2019-01-30T18:19:30Z</dc:date>
    </item>
    <item>
      <title>Re: PROC MEANS, how to identify the observations that belong to one row in the output table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-MEANS-how-to-identify-the-observations-that-belong-to-one/m-p/531495#M145466</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/127222"&gt;@acordes&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The number of iterations of the innermost DO loop is a random number. In addition to a generic ("unsuspicious") seed value for the CALL STREAMINIT routine I used the CALL STREAM routine in order to specify a random-number stream. I had tested the arguments 1, 2, ..., 1000 for CALL STREAM and &lt;EM&gt;selected&lt;/EM&gt; one (268) that &lt;EM&gt;happened to yield exactly 100 observations&lt;/EM&gt;, as desired (knowing that this might look somewhat mysterious to the attentive reader). &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;The reason that the IDs are free of duplicates is essentially the number-theoretic fact that the &lt;A href="https://en.wikipedia.org/wiki/Multiplicative_order" target="_blank" rel="noopener"&gt;multiplicative order&lt;/A&gt; of 67 modulo 101 is 100. Again, I had tried a few candidates and picked 67. Multiplying the powers of 67 by 5 (modulo 101) doesn't create duplicates either because 101 is a prime number and hence the ring of integers modulo 101 is a field (a fact that I knew from algebra).&lt;/P&gt;</description>
      <pubDate>Wed, 30 Jan 2019 22:50:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-MEANS-how-to-identify-the-observations-that-belong-to-one/m-p/531495#M145466</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-01-30T22:50:40Z</dc:date>
    </item>
  </channel>
</rss>

