<?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: Access data between tables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Classify-dataset-by-deciles/m-p/655552#M196671</link>
    <description>&lt;P&gt;Other than creating text values (likely not a best idea ) Proc Ranks will do this.&lt;/P&gt;
&lt;PRE&gt;proc ranks data=test1 groups=10
   out=want;
   var ptb  ;
   ranks ptbtile;
run;&lt;/PRE&gt;
&lt;P&gt;The variable ptbtile will have values of 0 to 9 (10 groups).&lt;/P&gt;
&lt;P&gt;Assign a format to display the value of '1st decile' if needed (decile would be more descriptive then "1st percentile" as that would indicate the P1 not P10 cutoff.&lt;/P&gt;</description>
    <pubDate>Tue, 09 Jun 2020 15:22:47 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2020-06-09T15:22:47Z</dc:date>
    <item>
      <title>Classify dataset by deciles</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Classify-dataset-by-deciles/m-p/655548#M196669</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm pretty new to SAS programming language and I would need advice about the best practice in the following problem. I have this table containing cut-off values of a percentile distribution:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc univariate data=temp1 noprint;
   var ptb;
   output out=percentiles1 pctlpts=10 20 30 40 50 60 70 80 90 100 pctlpre=P;
run;
proc print data=percentiles1;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Now, I would like to iterate over "temp1" table and decide in which bucket fits. I tried something like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp2 (drop = p10 p20 p30 p40 p50 p60 p70  p80 p90 p100);
merge temp1 percentiles1;
if ptb &amp;lt;= p10 then bucket = '1st percentile';
else if ptb &amp;lt;= p20 then bucket = '2nd percentile';
... and so on ...
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But this would work only for the first row. I was thinking to do a cross join in SQL, but I think it's not the best approach to copy the row of percentiles everywhere.&lt;/P&gt;&lt;P&gt;So, what would be the best approach?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jun 2020 08:53:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Classify-dataset-by-deciles/m-p/655548#M196669</guid>
      <dc:creator>littlewho</dc:creator>
      <dc:date>2020-06-10T08:53:34Z</dc:date>
    </item>
    <item>
      <title>Re: Access data between tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Classify-dataset-by-deciles/m-p/655552#M196671</link>
      <description>&lt;P&gt;Other than creating text values (likely not a best idea ) Proc Ranks will do this.&lt;/P&gt;
&lt;PRE&gt;proc ranks data=test1 groups=10
   out=want;
   var ptb  ;
   ranks ptbtile;
run;&lt;/PRE&gt;
&lt;P&gt;The variable ptbtile will have values of 0 to 9 (10 groups).&lt;/P&gt;
&lt;P&gt;Assign a format to display the value of '1st decile' if needed (decile would be more descriptive then "1st percentile" as that would indicate the P1 not P10 cutoff.&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jun 2020 15:22:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Classify-dataset-by-deciles/m-p/655552#M196671</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-06-09T15:22:47Z</dc:date>
    </item>
    <item>
      <title>Re: Access data between tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Classify-dataset-by-deciles/m-p/655557#M196674</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/333001"&gt;@littlewho&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm pretty new to SAS programming language and I would need advice about the best practice in the following problem. I have this table containing cut-off values of a percentile distribution:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc univariate data=temp1 noprint;
   var ptb;
   output out=percentiles1 pctlpts=10 20 30 40 50 60 70 80 90 100 pctlpre=P;
run;
proc print data=percentiles1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now, I would like to iterate over "temp1" table and decide in which bucket fits. I tried something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp2 (drop = p10 p20 p30 p40 p50 p60 p70  p80 p90 p100);
merge temp1 percentiles1;
if ptb &amp;lt;= p10 then bucket = '1st percentile';
else if ptb &amp;lt;= p20 then bucket = '2nd percentile';
... and so on ...
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But this would work only for the first row. I was thinking to do a cross join in SQL, but I think it's not the best approach to copy the row of percentiles everywhere.&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF6600"&gt;&lt;STRONG&gt;So, what would be the best approach?&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Neither of these. Use PROC RANK instead. 0 will correspond to the first decile, 1 to the second decile and so forth.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?docsetId=proc&amp;amp;docsetVersion=9.4&amp;amp;docsetTarget=p1xzpoijq32wbsn1gr6g5cx3emsx.htm&amp;amp;locale=en"&gt;https://documentation.sas.com/?docsetId=proc&amp;amp;docsetVersion=9.4&amp;amp;docsetTarget=p1xzpoijq32wbsn1gr6g5cx3emsx.htm&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc rank data=temp1 out=temp2 groups=10;
var ptb
ranks ptb_rank;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To fix your code, you need to merge it to all rows which is accomplished with a little code trick.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data temp2 (drop = p10 p20 p30 p40 p50 p60 p70  p80 p90 p100);
&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;set temp1;
if _n_ =1 then set percentiles1;&lt;/STRONG&gt;&lt;/FONT&gt;
if ptb &amp;lt;= p10 then bucket = '1st percentile';
else if ptb &amp;lt;= p20 then bucket = '2nd percentile';
... and so on ...
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jun 2020 15:29:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Classify-dataset-by-deciles/m-p/655557#M196674</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-06-09T15:29:21Z</dc:date>
    </item>
    <item>
      <title>Re: Access data between tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Classify-dataset-by-deciles/m-p/656248#M196773</link>
      <description>&lt;P&gt;EDIT: solved, I had to use "by" groups&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you know if there is any way to use 'class' keyword with proc ranks?&lt;BR /&gt;I would like the ranking to be done separately for each different date.&lt;BR /&gt;I obtained the cut-off values using proc univariate with class and it looks good, but I would also need something similar for ranking.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jun 2020 09:27:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Classify-dataset-by-deciles/m-p/656248#M196773</guid>
      <dc:creator>littlewho</dc:creator>
      <dc:date>2020-06-10T09:27:56Z</dc:date>
    </item>
    <item>
      <title>Re: Access data between tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Classify-dataset-by-deciles/m-p/656513#M196846</link>
      <description>You can have multiple variables in your BY statement so just add the date to the BY statement.</description>
      <pubDate>Wed, 10 Jun 2020 18:41:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Classify-dataset-by-deciles/m-p/656513#M196846</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-06-10T18:41:14Z</dc:date>
    </item>
  </channel>
</rss>

