<?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 mean with a where clause with median in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-mean-with-a-where-clause-with-median/m-p/760334#M240428</link>
    <description>&lt;P&gt;Your step 1 has no value. Don't do it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To replace missings with mean, median, sum, range, &lt;EM&gt;etc&lt;/EM&gt;., use PROC STDIZE&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=cleanfinal;
    by groups;
run;

proc stdize data=cleanfinal(where=(20&amp;lt;=kilograms&amp;lt;=40 or missing(kilograms))) method=median out=cleanfinal1 reponly;    
    by groups;
    var kilograms;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 09 Aug 2021 11:28:51 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2021-08-09T11:28:51Z</dc:date>
    <item>
      <title>proc mean with a where clause with median</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-mean-with-a-where-clause-with-median/m-p/760304#M240410</link>
      <description>&lt;PRE&gt;input group$ kilograms;

cards;

A 53.4

B 76.3

A 45.3

A 98.4

a 67.3

A 98.3

A 68.3

B 28.4

B 67.3

B 37.4

A 68.3

A 79.2

A 56.4

run;&lt;BR /&gt;/*1. Create a new dataset called cleanfinal from cleandata.*/&lt;BR /&gt;data cleanfinal;&lt;BR /&gt;set cleanme;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;2. Set values for the Kilograms variable to between 20 and 40, inclusively.&lt;BR /&gt;Data cleanfinal;&lt;BR /&gt;set cleanme;&lt;BR /&gt;where kilograms between 20 and 40;&lt;BR /&gt;Run;&lt;BR /&gt;&lt;BR /&gt;/*3. If values in Kilograms are missing, or not in the 20 to 40 range, &lt;BR /&gt;replace with the median Kilograms value found in Step 2. &lt;BR /&gt;(hint: you will do some conditional logic for Group 'A' and 'B', &lt;BR /&gt;and you will set a median kilograms for A and B)*/&lt;BR /&gt;&lt;BR /&gt;/*This is how I have done it*/&lt;BR /&gt;Proc means data=cleanfinal;&lt;BR /&gt;where missing (kilograms) or not (kilograms between 20 and 40) median;&lt;BR /&gt;var kilograms;&lt;BR /&gt;class groups;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;
&lt;P&gt;Last step gives errors and I don't know how to fix it. I have read many thing about proc mean since morning on and off.&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;blueblue&lt;/P&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;
&lt;P&gt;3. If values in Kilograms are missing, or not in the 20 to 40 range, replace with the median Kilograms value found in Step 2. (hint: you will do some conditional logic for Group 'A' and 'B', and you will set a median kilograms for A and B)&lt;/P&gt;</description>
      <pubDate>Mon, 09 Aug 2021 03:39:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-mean-with-a-where-clause-with-median/m-p/760304#M240410</guid>
      <dc:creator>GN0001</dc:creator>
      <dc:date>2021-08-09T03:39:39Z</dc:date>
    </item>
    <item>
      <title>Re: proc mean with a where clause with median</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-mean-with-a-where-clause-with-median/m-p/760305#M240411</link>
      <description>&lt;P&gt;The problem is that you cannot use where clause inside Proc means. Use it data little bit modified.&lt;/P&gt;
&lt;PRE&gt;Proc means data=cleanfinal(where= (kilograms = .  or not (kilograms between 20 and 40))= median;&lt;BR /&gt;var kilograms;&lt;BR /&gt;class groups;&lt;BR /&gt;run;&lt;/PRE&gt;
&lt;P&gt;,&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Aug 2021 04:21:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-mean-with-a-where-clause-with-median/m-p/760305#M240411</guid>
      <dc:creator>Aku</dc:creator>
      <dc:date>2021-08-09T04:21:40Z</dc:date>
    </item>
    <item>
      <title>Re: proc mean with a where clause with median</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-mean-with-a-where-clause-with-median/m-p/760313#M240416</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/289881"&gt;@Aku&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;The problem is that you cannot use where clause inside Proc means. Use it data little bit modified.&lt;/P&gt;
&lt;PRE&gt;Proc means data=cleanfinal(where= (kilograms = .  or not (kilograms between 20 and 40))= median;&lt;BR /&gt;var kilograms;&lt;BR /&gt;class groups;&lt;BR /&gt;run;&lt;/PRE&gt;
&lt;P&gt;,&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Sorry, but this is &lt;STRONG&gt;wrong&lt;/STRONG&gt;. Using where-clause inside proc means is not the problem. The problem is the word "median" at the end of the where statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/202329"&gt;@GN0001&lt;/a&gt; : Please post the full log, so that we see the errors. Also note that the description of the 3rd task is strange: &lt;/P&gt;
&lt;PRE&gt;If values in Kilograms are missing, or not in the 20 to 40 range,&amp;nbsp;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;if a value is in the mentioned range, it can't be missing.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Aug 2021 05:50:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-mean-with-a-where-clause-with-median/m-p/760313#M240416</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-08-09T05:50:57Z</dc:date>
    </item>
    <item>
      <title>Re: proc mean with a where clause with median</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-mean-with-a-where-clause-with-median/m-p/760334#M240428</link>
      <description>&lt;P&gt;Your step 1 has no value. Don't do it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To replace missings with mean, median, sum, range, &lt;EM&gt;etc&lt;/EM&gt;., use PROC STDIZE&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=cleanfinal;
    by groups;
run;

proc stdize data=cleanfinal(where=(20&amp;lt;=kilograms&amp;lt;=40 or missing(kilograms))) method=median out=cleanfinal1 reponly;    
    by groups;
    var kilograms;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 09 Aug 2021 11:28:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-mean-with-a-where-clause-with-median/m-p/760334#M240428</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-08-09T11:28:51Z</dc:date>
    </item>
    <item>
      <title>Re: proc mean with a where clause with median</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-mean-with-a-where-clause-with-median/m-p/760348#M240432</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;rightfully points out, you can automate and combine the last two steps of your assignment.&amp;nbsp; However, for learning purposes, you do need to be able to do each of the steps separately.&amp;nbsp; That being said, you are closer than you think.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First, the problem is not the WHERE clause, and it is not the word MEDIAN.&amp;nbsp; It is the equal sign before the word MEDIAN.&amp;nbsp; Just remove it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second, the CLASS statement has to refer to an existing variable.&amp;nbsp; Here, you refer to GROUPS which does not exist in the data.&amp;nbsp; Change it to GROUP and you should be all set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This assumes that the very beginning of your program actually spells out the name of the data set you want to create, along the lines of:&lt;/P&gt;
&lt;P&gt;data cleanme;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It also assumes you are going to take the report of the medians, and type those values back into the program to re-set out-of-range values.&amp;nbsp; You are doing the typing, and not automating the re-setting of out-of-range values.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Aug 2021 12:35:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-mean-with-a-where-clause-with-median/m-p/760348#M240432</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2021-08-09T12:35:49Z</dc:date>
    </item>
    <item>
      <title>Re: proc mean with a where clause with median</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-mean-with-a-where-clause-with-median/m-p/760351#M240434</link>
      <description>&lt;P&gt;I don't understand the assignment.&lt;/P&gt;
&lt;P&gt;It mentions using the median found in step 2, but step 2 says nothing about finding a median.&lt;/P&gt;
&lt;P&gt;Are you expected to find separate medians for the different groups?&lt;/P&gt;
&lt;P&gt;Should those medians be calculated on the full set of values?&amp;nbsp; Or just the values between 20 and 40?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Aug 2021 12:49:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-mean-with-a-where-clause-with-median/m-p/760351#M240434</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-08-09T12:49:37Z</dc:date>
    </item>
    <item>
      <title>Re: proc mean with a where clause with median</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-mean-with-a-where-clause-with-median/m-p/760723#M240573</link>
      <description>&lt;P&gt;Hello PaigeMiller,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It says:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;If values in Kilograms are missing, or not in the 20 to 40 range, &lt;BR /&gt;replace with the median Kilograms value found in Step 2. &lt;BR /&gt;(hint: you will do some conditional logic for Group 'A' and 'B', &lt;BR /&gt;and you will set a median kilograms for A and B&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Your where clause says:&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;where=(20&amp;lt;=kilograms&amp;lt;=40&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;while the request is not in the 20 to 40 range. Don't we need to add a not prior to where=(20&amp;lt;=kilograms&amp;lt;=40)?&lt;/P&gt;
&lt;P&gt;I can understand the question itself. Does it mean give a median for group a and group b when the range is not between 20 and 40?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;This is what I have and it doesn't produce correct results:

proc stdize date=cleanfinal1 method=median reponly;
where missing(kilograms) or not (kilograms between 20 and 40);
by group;
var kilograms;
run;&lt;/PRE&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;blueblue&lt;/P&gt;</description>
      <pubDate>Tue, 10 Aug 2021 18:36:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-mean-with-a-where-clause-with-median/m-p/760723#M240573</guid>
      <dc:creator>GN0001</dc:creator>
      <dc:date>2021-08-10T18:36:55Z</dc:date>
    </item>
    <item>
      <title>Re: proc mean with a where clause with median</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-mean-with-a-where-clause-with-median/m-p/760724#M240574</link>
      <description>&lt;P&gt;I think you are correct, you would need to add NOT into the code in that case&lt;/P&gt;</description>
      <pubDate>Tue, 10 Aug 2021 18:36:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-mean-with-a-where-clause-with-median/m-p/760724#M240574</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-08-10T18:36:23Z</dc:date>
    </item>
    <item>
      <title>Re: proc mean with a where clause with median</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-mean-with-a-where-clause-with-median/m-p/760726#M240575</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;The code doesn't give the correct result though:&lt;/P&gt;
&lt;P&gt;Is the question requiring to give a median for each group when kilogram is missing and range is not between 20 and 40?&lt;/P&gt;
&lt;P&gt;Please advise me.&lt;/P&gt;
&lt;P&gt;I need to take off the out data set to get the cleanfinal1 to have results. please try it.&lt;/P&gt;
&lt;P&gt;Also, the result is not correct. please test it.&lt;/P&gt;
&lt;P&gt;blueblue&lt;/P&gt;</description>
      <pubDate>Tue, 10 Aug 2021 18:51:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-mean-with-a-where-clause-with-median/m-p/760726#M240575</guid>
      <dc:creator>GN0001</dc:creator>
      <dc:date>2021-08-10T18:51:46Z</dc:date>
    </item>
    <item>
      <title>Re: proc mean with a where clause with median</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-mean-with-a-where-clause-with-median/m-p/760727#M240576</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=cleanfinal;
    by groups;
run;

/* when kilograms &amp;lt; 20 or &amp;gt; 40, set to missing */
data cleanfinal;
    set cleanfinal;
    if kilograms&amp;lt;20 or kilograms&amp;gt;40 then call missing(kilograms);
run;

/* Replace missings with medians of non-missing */
proc stdize data=cleanfinal method=median out=cleanfinal1 reponly;    
    by groups;
    var kilograms;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Aug 2021 18:57:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-mean-with-a-where-clause-with-median/m-p/760727#M240576</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-08-10T18:57:18Z</dc:date>
    </item>
  </channel>
</rss>

