<?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: Restricting 'WHERE' statement to one variable in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/PROC-MEANS-Restricting-WHERE-statement-to-one-variable/m-p/303377#M60784</link>
    <description>&lt;P&gt;Missing values aren't included in proc means calculations by default.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A where statment applies to the whole dataset. You can't have it selectively apply to some variables and not orhers.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 08 Oct 2016 17:42:01 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2016-10-08T17:42:01Z</dc:date>
    <item>
      <title>PROC MEANS: Restricting 'WHERE' statement to one variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-MEANS-Restricting-WHERE-statement-to-one-variable/m-p/303374#M60783</link>
      <description>&lt;P&gt;Hi, I'm new to SAS programming, and I'm having some trouble figuring out how to run PROC MEANS on multiple variables while limiting a WHERE statement to only one variable.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the context: My sample has 80 observations. I have two variables that I would like to run PROC MEANS on. 'Sleep' is the number of hours slept per day, and 'Age' is age in years. 'Sleep' has two outliers due to data entry errors (0 and 100), and the variable 'Sleep2' is dichotomous and excludes the two outliers (that is, if 'Sleep'&amp;lt;1 or 'Sleep'&amp;gt;12, then 'Sleep2'=.). 'Age' has no outliers that need to be excluded.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The following code runs:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc means;&lt;/P&gt;&lt;P&gt;var sleep age;&lt;/P&gt;&lt;P&gt;where sleep2^=.;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, this WHERE statement takes out the two observations for the entire procedure (it affects PROC MEANS on 'sleep' and 'age'). I only want to restrict this to the variable 'sleep' (PROC MEANS for 'sleep' has the 78 observations without the outliers, whereas PROC MEANS for 'age' has all 80 observations). I tried out something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc means;&lt;/P&gt;&lt;P&gt;var sleep (where=(sleep2^=.)) age;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This did not work. I know I can do this in two separate procedures (one procedure for 'sleep', another procedure for 'age'), but I would prefer to do this at once. Any advice or help?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 08 Oct 2016 16:15:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-MEANS-Restricting-WHERE-statement-to-one-variable/m-p/303374#M60783</guid>
      <dc:creator>archimboldi</dc:creator>
      <dc:date>2016-10-08T16:15:51Z</dc:date>
    </item>
    <item>
      <title>Re: PROC MEANS: Restricting 'WHERE' statement to one variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-MEANS-Restricting-WHERE-statement-to-one-variable/m-p/303377#M60784</link>
      <description>&lt;P&gt;Missing values aren't included in proc means calculations by default.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A where statment applies to the whole dataset. You can't have it selectively apply to some variables and not orhers.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 08 Oct 2016 17:42:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-MEANS-Restricting-WHERE-statement-to-one-variable/m-p/303377#M60784</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-10-08T17:42:01Z</dc:date>
    </item>
    <item>
      <title>Re: PROC MEANS: Restricting 'WHERE' statement to one variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-MEANS-Restricting-WHERE-statement-to-one-variable/m-p/303381#M60785</link>
      <description>&lt;P&gt;Thanks for your input. Since a WHERE statement can't do it, is there any way to do one PROC MEANS procedure for multiple variables while restricting one variable (ex: 'sleep' if 'sleep'&amp;gt;0) but not for another?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Not SAS code exactly, but imagine something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc means;&lt;/P&gt;&lt;P&gt;var sleep (if sleep&amp;gt;0) age;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 08 Oct 2016 18:01:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-MEANS-Restricting-WHERE-statement-to-one-variable/m-p/303381#M60785</guid>
      <dc:creator>archimboldi</dc:creator>
      <dc:date>2016-10-08T18:01:59Z</dc:date>
    </item>
    <item>
      <title>Re: PROC MEANS: Restricting 'WHERE' statement to one variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-MEANS-Restricting-WHERE-statement-to-one-variable/m-p/303382#M60786</link>
      <description>&lt;P&gt;No, you can't do what you're trying to do.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need to run multiple proc means.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 08 Oct 2016 18:05:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-MEANS-Restricting-WHERE-statement-to-one-variable/m-p/303382#M60786</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-10-08T18:05:18Z</dc:date>
    </item>
    <item>
      <title>Re: PROC MEANS: Restricting 'WHERE' statement to one variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-MEANS-Restricting-WHERE-statement-to-one-variable/m-p/303386#M60787</link>
      <description>&lt;P&gt;Try this &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;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/*Using for example instream dataset otherwise if you have SAS dataset, then SET statement*/&lt;BR /&gt;/* OPTION 1- Set outliers to missing in DATA step if you want the outliers to be replaced with missing values*/&lt;BR /&gt;/* OPTION 2- You need not set outliers to missing but subsetting WHERE statement in PROC MEANS works fine*/&lt;BR /&gt;DATA outliers;&lt;BR /&gt; INFILE DATALINES;&lt;BR /&gt; INPUT sleep age @@;&lt;BR /&gt; IF (sleep LT 1 OR sleep GT 12) THEN sleep=.; &lt;BR /&gt;DATALINES;&lt;BR /&gt;1 20 3 40 12 30&lt;BR /&gt;13 40 9 90 &lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;/P&gt;
&lt;P&gt;/*Print data to see if outliers are replaced with missing values*/&lt;BR /&gt;PROC PRINT DATA=outliers NOOBS;&lt;BR /&gt;RUN;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;PROC MEANS DATA=outliers; &lt;BR /&gt; VAR sleep age; &lt;BR /&gt; WHERE sleep GE 1 AND sleep LE 12;&lt;BR /&gt;RUN;&lt;/P&gt;</description>
      <pubDate>Sat, 08 Oct 2016 18:18:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-MEANS-Restricting-WHERE-statement-to-one-variable/m-p/303386#M60787</guid>
      <dc:creator>kenedy_yc</dc:creator>
      <dc:date>2016-10-08T18:18:08Z</dc:date>
    </item>
    <item>
      <title>Re: PROC MEANS: Restricting 'WHERE' statement to one variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-MEANS-Restricting-WHERE-statement-to-one-variable/m-p/303388#M60788</link>
      <description>&lt;P&gt;Record 13 is excluded from age calculations as well. Which isn't what the OP wants.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 08 Oct 2016 19:00:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-MEANS-Restricting-WHERE-statement-to-one-variable/m-p/303388#M60788</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-10-08T19:00:34Z</dc:date>
    </item>
    <item>
      <title>Re: PROC MEANS: Restricting 'WHERE' statement to one variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-MEANS-Restricting-WHERE-statement-to-one-variable/m-p/303389#M60789</link>
      <description>From subsetting condition  "... that is, if 'Sleep'&amp;lt;1 or 'Sleep'&amp;gt;12, then 'Sleep2'=. " seems sleep takes on positive values in the range 1 to 12 ?</description>
      <pubDate>Sat, 08 Oct 2016 19:37:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-MEANS-Restricting-WHERE-statement-to-one-variable/m-p/303389#M60789</guid>
      <dc:creator>kenedy_yc</dc:creator>
      <dc:date>2016-10-08T19:37:33Z</dc:date>
    </item>
    <item>
      <title>Re: PROC MEANS: Restricting 'WHERE' statement to one variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-MEANS-Restricting-WHERE-statement-to-one-variable/m-p/303392#M60790</link>
      <description>&lt;P&gt;Yes, but age is also restricted.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With the WHERE clause the average age is 45.&lt;/P&gt;
&lt;P&gt;Without a WHERE clause the average age is 44. The WHERE removes that entire record from the analysis, which is what the OP would like to avoid.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
title 'With WHERE';
PROC MEANS DATA=outliers; 
VAR sleep age; 
WHERE sleep GE 1 AND sleep LE 12;
RUN;


title 'Without WHERE';
proc means data=outliers;
var sleep age;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Results here:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;SECTION data-name="Means" data-sec-type="proc"&gt;
&lt;DIV id="IDX" class="systitleandfootercontainer"&gt;
&lt;P&gt;&lt;SPAN class="c systemtitle"&gt;With WHERE&lt;/SPAN&gt;&lt;/P&gt;
&lt;/DIV&gt;
&lt;ARTICLE&gt;
&lt;TABLE class="table"&gt;&lt;COLGROUP&gt;&lt;COL /&gt;&lt;/COLGROUP&gt;&lt;COLGROUP&gt;&lt;COL /&gt;&lt;COL /&gt;&lt;COL /&gt;&lt;COL /&gt;&lt;COL /&gt;&lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="b header" scope="col"&gt;Variable&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;N&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;Mean&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;Std Dev&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;Minimum&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;Maximum&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="data"&gt;
&lt;DIV class="stacked-cell"&gt;
&lt;DIV&gt;sleep&lt;/DIV&gt;
&lt;DIV&gt;age&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/TH&gt;
&lt;TD class="r data"&gt;
&lt;DIV class="stacked-cell"&gt;
&lt;DIV&gt;4&lt;/DIV&gt;
&lt;DIV&gt;4&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/TD&gt;
&lt;TD class="r data"&gt;
&lt;DIV class="stacked-cell"&gt;
&lt;DIV&gt;6.2500000&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;45.0000000&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/TD&gt;
&lt;TD class="r data"&gt;
&lt;DIV class="stacked-cell"&gt;
&lt;DIV&gt;5.1234754&lt;/DIV&gt;
&lt;DIV&gt;31.0912635&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/TD&gt;
&lt;TD class="r data"&gt;
&lt;DIV class="stacked-cell"&gt;
&lt;DIV&gt;1.0000000&lt;/DIV&gt;
&lt;DIV&gt;20.0000000&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/TD&gt;
&lt;TD class="r data"&gt;
&lt;DIV class="stacked-cell"&gt;
&lt;DIV&gt;12.0000000&lt;/DIV&gt;
&lt;DIV&gt;90.0000000&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/ARTICLE&gt;
&lt;/SECTION&gt;
&lt;SECTION data-name="Means" data-sec-type="proc"&gt;&lt;HR /&gt;
&lt;DIV id="IDX1" class="systitleandfootercontainer"&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="c systemtitle"&gt;Without WHERE&lt;/SPAN&gt;&lt;/P&gt;
&lt;/DIV&gt;
&lt;ARTICLE&gt;
&lt;TABLE class="table"&gt;&lt;COLGROUP&gt;&lt;COL /&gt;&lt;/COLGROUP&gt;&lt;COLGROUP&gt;&lt;COL /&gt;&lt;COL /&gt;&lt;COL /&gt;&lt;COL /&gt;&lt;COL /&gt;&lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="b header" scope="col"&gt;Variable&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;N&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;Mean&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;Std Dev&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;Minimum&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;Maximum&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="data"&gt;
&lt;DIV class="stacked-cell"&gt;
&lt;DIV&gt;sleep&lt;/DIV&gt;
&lt;DIV&gt;age&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/TH&gt;
&lt;TD class="r data"&gt;
&lt;DIV class="stacked-cell"&gt;
&lt;DIV&gt;4&lt;/DIV&gt;
&lt;DIV&gt;5&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/TD&gt;
&lt;TD class="r data"&gt;
&lt;DIV class="stacked-cell"&gt;
&lt;DIV&gt;6.2500000&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;44.0000000&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/TD&gt;
&lt;TD class="r data"&gt;
&lt;DIV class="stacked-cell"&gt;
&lt;DIV&gt;5.1234754&lt;/DIV&gt;
&lt;DIV&gt;27.0185122&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/TD&gt;
&lt;TD class="r data"&gt;
&lt;DIV class="stacked-cell"&gt;
&lt;DIV&gt;1.0000000&lt;/DIV&gt;
&lt;DIV&gt;20.0000000&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/TD&gt;
&lt;TD class="r data"&gt;
&lt;DIV class="stacked-cell"&gt;
&lt;DIV&gt;12.0000000&lt;/DIV&gt;
&lt;DIV&gt;90.0000000&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/ARTICLE&gt;
&lt;/SECTION&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 08 Oct 2016 20:03:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-MEANS-Restricting-WHERE-statement-to-one-variable/m-p/303392#M60790</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-10-08T20:03:17Z</dc:date>
    </item>
    <item>
      <title>Re: PROC MEANS: Restricting 'WHERE' statement to one variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-MEANS-Restricting-WHERE-statement-to-one-variable/m-p/303446#M60792</link>
      <description>&lt;P&gt;Thanks Reeza. Much clearer now. I think the author of the&amp;nbsp;question didn't make state it clearly from the start.&lt;/P&gt;</description>
      <pubDate>Sun, 09 Oct 2016 08:51:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-MEANS-Restricting-WHERE-statement-to-one-variable/m-p/303446#M60792</guid>
      <dc:creator>kenedy_yc</dc:creator>
      <dc:date>2016-10-09T08:51:12Z</dc:date>
    </item>
    <item>
      <title>Re: PROC MEANS: Restricting 'WHERE' statement to one variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-MEANS-Restricting-WHERE-statement-to-one-variable/m-p/303483#M60793</link>
      <description>&lt;P&gt;Create an intermediate view that will effectively remove outlying values :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data validData / view=validData;
set wholeData;
if sleep &amp;lt;1 or sleep &amp;gt; 12 then call missing (sleep);
run;

proc means data=validData;
var sleep age;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 10 Oct 2016 02:35:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-MEANS-Restricting-WHERE-statement-to-one-variable/m-p/303483#M60793</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-10-10T02:35:16Z</dc:date>
    </item>
  </channel>
</rss>

