<?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: percentiles by group that is defined by 2 fields in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/percentiles-by-group-that-is-defined-by-2-fields/m-p/816607#M322350</link>
    <description>&lt;P&gt;In oldfmt, the values 10 and 20 appear in two ranges each, so the multilabel-capable PROC SUMMARY will honor that. This may cause incorrect calculations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regarding the duplicates:&lt;/P&gt;
&lt;P&gt;By sorting and using BY instead of CLASS, the combination of 2 and 10 appears before 2 and 15, but much later you get 3 and 10, which falls into the same formatted range as&amp;nbsp; and 10. But then the values for the group have already been calculated once, so you get a second entry.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Fix your format definition, and use CLASS and the NWAY option in the PROC SUMMARY statement.&lt;/P&gt;</description>
    <pubDate>Mon, 06 Jun 2022 08:07:54 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2022-06-06T08:07:54Z</dc:date>
    <item>
      <title>percentiles by group that is defined by 2 fields</title>
      <link>https://communities.sas.com/t5/SAS-Programming/percentiles-by-group-that-is-defined-by-2-fields/m-p/816596#M322347</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I want to calculate percentiles (P50,P70,P80,P90)&amp;nbsp; for each group.&lt;/P&gt;
&lt;P&gt;The group is defined by the fields old and gk.&lt;/P&gt;
&lt;P&gt;There is a problem in the result of the following code:&lt;/P&gt;
&lt;P&gt;I get duplication of groups.&lt;/P&gt;
&lt;P&gt;For example: For&amp;nbsp; gk='(a) 2-3' I get 2 rows with old='(a) 0-10'&lt;/P&gt;
&lt;P&gt;What is the way to solve it please?&lt;/P&gt;
&lt;P&gt;Why did it happen?&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ronein_0-1654497618995.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/72004i95E9B12669EE6E4D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ronein_0-1654497618995.png" alt="Ronein_0-1654497618995.png" /&gt;&lt;/span&gt;&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;
data have;
input gk old New;
cards;
2 10 15
2 15 22
2 20 25
2 17 19
2 19 17
2 31 35
2 35 40
2 27 30
2 18 18
2 17 19
3 72 72
3 12 10
3 19 20
3 10 15
3 9 10
3 42 45
3 35 30
5 37 40
5 27 30
5 29 29
5 32 33
5 35 36
5 65 70
5 9 10
5 13 12
5 18 15
;
run;

proc format;
value gkfmt
2,3='(a) 2-3'
5='(b) 5'
;
Run;

proc format;
value old_fmt
0-10='(a) 0-10'
10-20='(b) 10-20'
20-high='(d) 20+'
;
Run;

proc sort data=have;
by gk old;
Run;

proc summary data=have;
by gk old ;
var new: ;
output out=want(drop=_type_) p50= p70= P80=  P90=/autoname;
format  old old_fmt.  gk gkfmt.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 Jun 2022 06:41:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/percentiles-by-group-that-is-defined-by-2-fields/m-p/816596#M322347</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2022-06-06T06:41:28Z</dc:date>
    </item>
    <item>
      <title>Re: percentiles by group that is defined by 2 fields</title>
      <link>https://communities.sas.com/t5/SAS-Programming/percentiles-by-group-that-is-defined-by-2-fields/m-p/816607#M322350</link>
      <description>&lt;P&gt;In oldfmt, the values 10 and 20 appear in two ranges each, so the multilabel-capable PROC SUMMARY will honor that. This may cause incorrect calculations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regarding the duplicates:&lt;/P&gt;
&lt;P&gt;By sorting and using BY instead of CLASS, the combination of 2 and 10 appears before 2 and 15, but much later you get 3 and 10, which falls into the same formatted range as&amp;nbsp; and 10. But then the values for the group have already been calculated once, so you get a second entry.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Fix your format definition, and use CLASS and the NWAY option in the PROC SUMMARY statement.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jun 2022 08:07:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/percentiles-by-group-that-is-defined-by-2-fields/m-p/816607#M322350</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-06-06T08:07:54Z</dc:date>
    </item>
    <item>
      <title>Re: percentiles by group that is defined by 2 fields</title>
      <link>https://communities.sas.com/t5/SAS-Programming/percentiles-by-group-that-is-defined-by-2-fields/m-p/816620#M322352</link>
      <description>&lt;P&gt;Thanks,I write the solution by your advice&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input gk old New;
cards;
2 10 15
2 15 22
2 20 25
2 17 19
2 19 17
2 31 35
2 35 40
2 27 30
2 18 18
2 17 19
3 72 72
3 12 10
3 19 20
3 10 15
3 9 10
3 42 45
3 35 30
5 37 40
5 27 30
5 29 29
5 32 33
5 35 36
5 65 70
5 9 10
5 13 12
5 18 15
;
run;
proc format;
value gkfmt
2,3='(a) 2-3'
5='(b) 5'
;
Run;
proc format;
value old_fmt
0-10='(a) 0-10'
10&amp;lt;-20='(b) 10-20'
20&amp;lt;-high='(d) 20+'
;
Run;

/**Way1**/
proc summary data=have nway;
class gk old ;
var new ;
output out=want(drop=_type_) p50= p70= P80=  P90=/autoname;
format  old old_fmt.  gk gkfmt.;
run;


/**Way2**/
proc sort data=have;
by gk old ;
Run;
proc summary data=have nway;
class gk old ;
var new ;
output out=want(drop=_type_) p50= p70= P80=  P90=/autoname;
format  old old_fmt.  gk gkfmt.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 Jun 2022 11:03:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/percentiles-by-group-that-is-defined-by-2-fields/m-p/816620#M322352</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2022-06-06T11:03:50Z</dc:date>
    </item>
    <item>
      <title>Re: percentiles by group that is defined by 2 fields</title>
      <link>https://communities.sas.com/t5/SAS-Programming/percentiles-by-group-that-is-defined-by-2-fields/m-p/816622#M322354</link>
      <description>As I see, if the value appear in 2 ranges (proc format) then the value will be allocated to first range.&lt;BR /&gt;Is it still "multilabel" case??&lt;BR /&gt;&lt;BR /&gt;data ttt;&lt;BR /&gt;input x;&lt;BR /&gt;cards;&lt;BR /&gt;9&lt;BR /&gt;9.9&lt;BR /&gt;10&lt;BR /&gt;15&lt;BR /&gt;19&lt;BR /&gt;20&lt;BR /&gt;25&lt;BR /&gt;40&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt; proc means data=ttt;&lt;BR /&gt; class x;&lt;BR /&gt; format x old_fmt.;&lt;BR /&gt; Run;</description>
      <pubDate>Mon, 06 Jun 2022 11:40:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/percentiles-by-group-that-is-defined-by-2-fields/m-p/816622#M322354</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2022-06-06T11:40:03Z</dc:date>
    </item>
  </channel>
</rss>

