<?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: How to create groups by deciles - weird results in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-create-groups-by-deciles-weird-results/m-p/306811#M61059</link>
    <description>&lt;P&gt;Note that using IF then as you have may well not result in what you want if you have much repitition of values.&lt;/P&gt;
&lt;P&gt;As an extreme example, if all of the data has the same value then P10=P20=P30=P40 and so forth&lt;/P&gt;
&lt;P&gt;This example&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data example;
   input x;
datalines;
1 
2
2
2
3
3
3
4
4
4
;
run;

proc univariate data=example;
  var x;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Shows that 4 would be at least P75, P80 P90 and P100. Your IF/then/else code will assign all values of 4 to the lowest percentile and none to the higher. If that is not the desired result then &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza﻿&lt;/a&gt;'s suggestion is much better.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 24 Oct 2016 14:28:44 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2016-10-24T14:28:44Z</dc:date>
    <item>
      <title>How to create groups by deciles - weird results</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-create-groups-by-deciles-weird-results/m-p/306699#M61042</link>
      <description>&lt;P&gt;I'm perfoming what should be a straightwoard series of proc and data steps to categorise the 'inc' variable into deciles (pls see below code). But the result seems to be giving me a bizarre lag between one row and another, which&amp;nbsp;makes no sense to me (pls see image). Please help!!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*calc and output deciles;
proc univariate data=mydata noprint;
var inc;
output out=percentiles pctlpre=P_ pctlpts= 10 to 90 by 10 ;
weight myweight;
run;

*merge on deciles;
data mydata;
if _n_=1 then set percentiles;
set  mydata;
run;

*assign decile category;
data mydata;
dec=0;
if inc &amp;lt;P_10 then dec =1;
if P_10&amp;lt; inc &amp;lt;P_20 then dec =2;
if P_20&amp;lt; inc &amp;lt;P_30 then dec =3;
if P_30&amp;lt; inc &amp;lt;P_40 then dec =4;
if P_40&amp;lt; inc &amp;lt;P_50 then dec =5;
if P_50&amp;lt; inc &amp;lt;P_60 then dec =6;
if P_60&amp;lt; inc &amp;lt;P_70 then dec =7;
if P_70&amp;lt; inc &amp;lt;P_80 then dec =8;
if P_80&amp;lt; inc &amp;lt;P_90 then dec =9;
if P_90&amp;lt; inc then dec =10;
set mydata;
run;

*test the weirdness;
data mydata;
testinc=inc;
set mydata;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/5451iE61ADA4FD5C4400F/image-size/original?v=v2&amp;amp;px=-1" border="0" alt="sasdata.png" title="sasdata.png" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Oct 2016 06:20:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-create-groups-by-deciles-weird-results/m-p/306699#M61042</guid>
      <dc:creator>rafonsas</dc:creator>
      <dc:date>2016-10-24T06:20:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to create groups by deciles - weird results</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-create-groups-by-deciles-weird-results/m-p/306700#M61043</link>
      <description>&lt;P&gt;Your last data step messes up data since set after variable assignment. Move set right after data step. Unless you wanted a lagged variable.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Otherwise, I'm not sure what's unexpected here.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also a good example of why each data step should generate a unique data set.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data mydata_test;;&lt;/P&gt;
&lt;P&gt;SET my_data;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;test_in = inc;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&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>Mon, 24 Oct 2016 06:47:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-create-groups-by-deciles-weird-results/m-p/306700#M61043</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-10-24T06:47:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to create groups by deciles - weird results</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-create-groups-by-deciles-weird-results/m-p/306705#M61046</link>
      <description>&lt;P&gt;Thank you, Reeza!! I see.&amp;nbsp;The second last&amp;nbsp;step&amp;nbsp;also had set statement at&amp;nbsp;the end, messing up the deciles too. Hadn't realised that it would have such an effect. Much appreciated.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Oct 2016 07:01:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-create-groups-by-deciles-weird-results/m-p/306705#M61046</guid>
      <dc:creator>rafonsas</dc:creator>
      <dc:date>2016-10-24T07:01:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to create groups by deciles - weird results</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-create-groups-by-deciles-weird-results/m-p/306706#M61047</link>
      <description>&lt;P&gt;Look at proc rank to calculate your deciles in one step.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Oct 2016 07:06:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-create-groups-by-deciles-weird-results/m-p/306706#M61047</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-10-24T07:06:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to create groups by deciles - weird results</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-create-groups-by-deciles-weird-results/m-p/306811#M61059</link>
      <description>&lt;P&gt;Note that using IF then as you have may well not result in what you want if you have much repitition of values.&lt;/P&gt;
&lt;P&gt;As an extreme example, if all of the data has the same value then P10=P20=P30=P40 and so forth&lt;/P&gt;
&lt;P&gt;This example&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data example;
   input x;
datalines;
1 
2
2
2
3
3
3
4
4
4
;
run;

proc univariate data=example;
  var x;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Shows that 4 would be at least P75, P80 P90 and P100. Your IF/then/else code will assign all values of 4 to the lowest percentile and none to the higher. If that is not the desired result then &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza﻿&lt;/a&gt;'s suggestion is much better.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Oct 2016 14:28:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-create-groups-by-deciles-weird-results/m-p/306811#M61059</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-10-24T14:28:44Z</dc:date>
    </item>
  </channel>
</rss>

