<?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: Coding kilograms by inclusive numbers and median in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Coding-kilograms-by-inclusive-numbers-and-median/m-p/925096#M364093</link>
    <description>&lt;P&gt;here is the code may helpful&lt;/P&gt;&lt;P&gt;data work.cleandata36;&lt;/P&gt;&lt;P&gt;set cert.input36;&lt;/P&gt;&lt;P&gt;group=upcase(group);&lt;/P&gt;&lt;P&gt;if group in ('A','B');&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc means data=work.cleandata36 median;&lt;/P&gt;&lt;P&gt;class group; var kilograms;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data results.output36;&lt;/P&gt;&lt;P&gt;set cleandata36;&lt;/P&gt;&lt;P&gt;if Kilograms &amp;lt; 40 or Kilograms &amp;gt; 200 then do;&lt;/P&gt;&lt;P&gt;if group='A' then kilograms=79;&lt;/P&gt;&lt;P&gt;else kilograms=89;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc contents data=results.output36; run;&lt;/P&gt;</description>
    <pubDate>Sat, 20 Apr 2024 14:20:19 GMT</pubDate>
    <dc:creator>simhayagnam</dc:creator>
    <dc:date>2024-04-20T14:20:19Z</dc:date>
    <item>
      <title>Coding kilograms by inclusive numbers and median</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Coding-kilograms-by-inclusive-numbers-and-median/m-p/651249#M195378</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am stuck on step 3 of the following problem on a practice exam:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;UL&gt;&lt;LI&gt;&lt;SPAN style="box-sizing: border-box; font-size: 0.93rem;"&gt;Step 1:&lt;/SPAN&gt;&lt;/LI&gt;&lt;UL&gt;&lt;LI&gt;create a temporary data set, &lt;STRONG&gt;cleandata36&lt;/STRONG&gt;.&lt;/LI&gt;&lt;LI&gt;In this data set, convert all &lt;STRONG&gt;group&lt;/STRONG&gt; values to upper case.&lt;/LI&gt;&lt;LI&gt;Then keep only observations with &lt;STRONG&gt;group&lt;/STRONG&gt; equal to 'A' or 'B'.&lt;/LI&gt;&lt;/UL&gt;&lt;/UL&gt;&lt;/UL&gt;&lt;UL&gt;&lt;UL&gt;&lt;LI&gt;Step 2:&lt;/LI&gt;&lt;UL&gt;&lt;LI&gt;Determine the MEDIAN value for the &lt;STRONG&gt;Kilograms&lt;/STRONG&gt; variable for each &lt;STRONG&gt;group&lt;/STRONG&gt;&amp;nbsp;(A,B) in the &lt;STRONG&gt;cleandata36&lt;/STRONG&gt; data set. Round MEDIAN to the nearest whole number.&lt;/LI&gt;&lt;/UL&gt;&lt;/UL&gt;&lt;/UL&gt;&lt;UL&gt;&lt;UL&gt;&lt;LI&gt;Step 3:&lt;/LI&gt;&lt;UL&gt;&lt;LI&gt;create &lt;STRONG&gt;results.output36&lt;/STRONG&gt; from &lt;STRONG&gt;cleandata36&lt;/STRONG&gt;&lt;/LI&gt;&lt;LI&gt;Ensure that all values for variable&amp;nbsp;&lt;STRONG&gt;Kilograms&lt;/STRONG&gt; are between 40 and 200, inclusively.&lt;/LI&gt;&lt;LI&gt;If the value is missing or out of range, replace the value with the MEDIAN &lt;STRONG&gt;Kilograms&lt;/STRONG&gt; value for the respective &lt;STRONG&gt;group&lt;/STRONG&gt; (A,B) calculated in step 2.&lt;/LI&gt;&lt;/UL&gt;&lt;/UL&gt;&lt;/UL&gt;&lt;P&gt;I was able to solve the first two steps, however, I am unable to solve the third based on the medians I have found. This is the code I have thus far:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data cleandata36;
set cert.input36;

Group=upcase(Group);

if Group='A' or Group='B' then output;

Run;

Proc means data= cleandata36 MEDIAN maxdec=0;
class group;
var Kilograms;

Run;

Data results.output36;
set cleandata36;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is appreciated, thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 28 May 2020 00:16:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Coding-kilograms-by-inclusive-numbers-and-median/m-p/651249#M195378</guid>
      <dc:creator>J_Moose</dc:creator>
      <dc:date>2020-05-28T00:16:52Z</dc:date>
    </item>
    <item>
      <title>Re: Coding kilograms by inclusive numbers and median</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Coding-kilograms-by-inclusive-numbers-and-median/m-p/651261#M195385</link>
      <description>&lt;P&gt;please try the proc stdsize procedure, here the missing values within the group will be replaced with the method specified. Since you have the method as median, the missing values within the group will be replaced with the median of that group as we used by statement as group. The reponly option does help in replacing only the missing values with median. A very good procedure perfect for your requirement and it helps you avoid the step2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS it is an untested code as i am not sure of your, so please test and let me know if it is working. Per your response I am assuming that we need to keep only kilograms between 40 and 200 inclusive and then get the median value and then replace the missing values with median. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data nonmissing missing;
set cleandata36;
if 40&amp;lt;=kilograms&amp;lt;=200 then output nonmissing;
if missing(kilograms) then output missing;
run;

data cleandata36_2;
set nonmissing missing;
run;

proc sort data=cleandata36_2;
by group;
run;

proc stdize data=cleandata36_2 out=results.output36 method=median reponly;
var kilograms;
by group;
run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 May 2020 02:08:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Coding-kilograms-by-inclusive-numbers-and-median/m-p/651261#M195385</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2020-05-28T02:08:53Z</dc:date>
    </item>
    <item>
      <title>Re: Coding kilograms by inclusive numbers and median</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Coding-kilograms-by-inclusive-numbers-and-median/m-p/651348#M195429</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/328154"&gt;@J_Moose&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;I think you could add an output statement in the PROC MEANS as follows:&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc means data=cleandata36 median maxdec=0;
var Kilograms;
class group;
ways 1;
output out=cleandata36_median (drop=_:) median=median; /*create a dataset that contains the median for each group*/
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;DIV&gt;Then you could merge your two datasets as follows to retrieve the value of the median for each observation according to its group, and then be able to input its value to "kilograms" when the condition is met.&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=cleandata36;&amp;nbsp;by group;&amp;nbsp;run;

data results.output36;
merge cleandata36 cleandata36_median;
by group;
if Kilograms &amp;lt; 40 or Kilograms &amp;gt; 200 then Kilograms = median;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;DIV&gt;Another possibility would be to hardcode the value of the median:&lt;/DIV&gt;
&lt;DIV&gt;&lt;CODE class=" language-sas"&gt;if Kilograms &amp;lt; 40 or Kilograms &amp;gt; 200 AND group="A" then Kilograms=xxx;&lt;/CODE&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;CODE class=" language-sas"&gt;else&amp;nbsp;Kilograms &amp;lt; 40 or Kilograms &amp;gt; 200 AND group="B" then Kilograms=yyy;&lt;/CODE&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;But it is definitely a bad habit, and makes your code less "dynamic".&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;Best,&lt;/DIV&gt;</description>
      <pubDate>Thu, 28 May 2020 11:03:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Coding-kilograms-by-inclusive-numbers-and-median/m-p/651348#M195429</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-05-28T11:03:38Z</dc:date>
    </item>
    <item>
      <title>Re: Coding kilograms by inclusive numbers and median</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Coding-kilograms-by-inclusive-numbers-and-median/m-p/694003#M211627</link>
      <description>Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12151"&gt;@Jagadishkatam&lt;/a&gt;, i have never come across proc stdize, Thank for sharing</description>
      <pubDate>Sat, 24 Oct 2020 14:38:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Coding-kilograms-by-inclusive-numbers-and-median/m-p/694003#M211627</guid>
      <dc:creator>himself</dc:creator>
      <dc:date>2020-10-24T14:38:38Z</dc:date>
    </item>
    <item>
      <title>Re: Coding kilograms by inclusive numbers and median</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Coding-kilograms-by-inclusive-numbers-and-median/m-p/845257#M334145</link>
      <description>&lt;P&gt;data result.output36;&lt;BR /&gt;set cleandata36;&lt;BR /&gt;if group='A' then do;&lt;BR /&gt;if kilograms LT 40 or kilograms GT 200 then kilograms="79";&lt;BR /&gt;end;&lt;BR /&gt;else if group='B' then do;&lt;BR /&gt;if kilograms LT 40 or kilograms GT 200 then kilograms='89';&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;BR /&gt;proc print data=result.output36;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Sat, 19 Nov 2022 11:35:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Coding-kilograms-by-inclusive-numbers-and-median/m-p/845257#M334145</guid>
      <dc:creator>Akash7210</dc:creator>
      <dc:date>2022-11-19T11:35:19Z</dc:date>
    </item>
    <item>
      <title>Re: Coding kilograms by inclusive numbers and median</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Coding-kilograms-by-inclusive-numbers-and-median/m-p/845282#M334166</link>
      <description>&lt;P&gt;Excellent suggestion from &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12151"&gt;@Jagadishkatam&lt;/a&gt; .&amp;nbsp; It doesn't get much simpler! &lt;/P&gt;</description>
      <pubDate>Sat, 19 Nov 2022 22:56:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Coding-kilograms-by-inclusive-numbers-and-median/m-p/845282#M334166</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-11-19T22:56:00Z</dc:date>
    </item>
    <item>
      <title>Re: Coding kilograms by inclusive numbers and median</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Coding-kilograms-by-inclusive-numbers-and-median/m-p/925096#M364093</link>
      <description>&lt;P&gt;here is the code may helpful&lt;/P&gt;&lt;P&gt;data work.cleandata36;&lt;/P&gt;&lt;P&gt;set cert.input36;&lt;/P&gt;&lt;P&gt;group=upcase(group);&lt;/P&gt;&lt;P&gt;if group in ('A','B');&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc means data=work.cleandata36 median;&lt;/P&gt;&lt;P&gt;class group; var kilograms;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data results.output36;&lt;/P&gt;&lt;P&gt;set cleandata36;&lt;/P&gt;&lt;P&gt;if Kilograms &amp;lt; 40 or Kilograms &amp;gt; 200 then do;&lt;/P&gt;&lt;P&gt;if group='A' then kilograms=79;&lt;/P&gt;&lt;P&gt;else kilograms=89;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc contents data=results.output36; run;&lt;/P&gt;</description>
      <pubDate>Sat, 20 Apr 2024 14:20:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Coding-kilograms-by-inclusive-numbers-and-median/m-p/925096#M364093</guid>
      <dc:creator>simhayagnam</dc:creator>
      <dc:date>2024-04-20T14:20:19Z</dc:date>
    </item>
  </channel>
</rss>

