<?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: Creating a format from a dataset based off a range of values? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-format-from-a-dataset-based-off-a-range-of-values/m-p/707535#M217253</link>
    <description>Thank you very much for this &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13642"&gt;@GertNissen&lt;/a&gt;. I wasn't sure if formats were the best way to do it but your solution was exactly what i'm looking for</description>
    <pubDate>Mon, 21 Dec 2020 17:28:23 GMT</pubDate>
    <dc:creator>denmcl94</dc:creator>
    <dc:date>2020-12-21T17:28:23Z</dc:date>
    <item>
      <title>Creating a format from a dataset based off a range of values?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-format-from-a-dataset-based-off-a-range-of-values/m-p/707511#M217235</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have two datasets, the first is a summary table of results from a proc rank for 20 different categories by up to two sub groups into 20 ranks&amp;nbsp;based off a particular score, and the max and min scores in that rank&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Category Group Rank Max Min&lt;/P&gt;&lt;P&gt;Y7&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Maths 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 10&lt;BR /&gt;Y7&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Maths 2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 10&amp;nbsp;&amp;nbsp; 17&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;Y8&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; English 9&amp;nbsp;&amp;nbsp;&amp;nbsp; 45&amp;nbsp;&amp;nbsp;&amp;nbsp; 52&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and so on&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;. the second is an independent table that has the category and the group on each row, with the continuous score in the same ranges as the max and mins. What I am trying to do is add the RANK column on to the second dataset. so if i had a student in Y7 who in their Maths test scored 5, they would get the RANK value 1. Without coding it in (theres 800 ish rows) i imagine there must be a way to create a format off the dataset that will do it for me but im struggling. Could someone help guide me towards the solution?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 21 Dec 2020 15:47:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-format-from-a-dataset-based-off-a-range-of-values/m-p/707511#M217235</guid>
      <dc:creator>denmcl94</dc:creator>
      <dc:date>2020-12-21T15:47:01Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a format from a dataset based off a range of values?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-format-from-a-dataset-based-off-a-range-of-values/m-p/707518#M217241</link>
      <description>&lt;P&gt;What do all of those columns in that report mean?&amp;nbsp; To make a format you need just one set of ranges. Such as :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format ;
value rank 0-10='1' 10-20='2' ... ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can then apply this format to numeric value and get the rank of that value.&lt;/P&gt;
&lt;P&gt;If you want the rank to be different for different values of CATEGORY and/or GROUP then using formats is probably not the best approach since you would need to make many formats.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Dec 2020 16:32:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-format-from-a-dataset-based-off-a-range-of-values/m-p/707518#M217241</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-12-21T16:32:51Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a format from a dataset based off a range of values?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-format-from-a-dataset-based-off-a-range-of-values/m-p/707527#M217247</link>
      <description>&lt;P&gt;Perhaps something like this would work for you &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/361551"&gt;@denmcl94&lt;/a&gt;&amp;nbsp;?&lt;BR /&gt;It's not using a SAS Format, but I guess it's something like this your looking for.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data rankdata;
  input Category $ Group $ Rank Max Min;
  datalines;
Y7 Maths 1 0 10
Y7 Maths 2 10 17
Y8 English 9 45 52
; 
run;

data independent_table ;
  input Category $ Group $ score;
  datalines;
Y7 Maths 8
Y7 Maths 14
Y8 English 50
Y7 Maths 2
Y7 Maths 11
Y8 English 45
Y7 Maths 20
Y7 Maths 0
Y8 English 60
; 
run;

proc sql;
  create table result as
  select indep.Category, indep.Group, indep.score
       , rankdata.Rank
  from independent_table as indep
  left join rankdata
    on indep.Category = rankdata.Category
    and indep.Group = rankdata.Group
    and indep.score between rankdata.min and rankdata.max;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result dataset&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Creating a format from a dataset based off a range of values.png" style="width: 259px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/52940i4895DA578B215CBC/image-size/large?v=v2&amp;amp;px=999" role="button" title="Creating a format from a dataset based off a range of values.png" alt="Creating a format from a dataset based off a range of values.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Dec 2020 16:57:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-format-from-a-dataset-based-off-a-range-of-values/m-p/707527#M217247</guid>
      <dc:creator>GertNissen</dc:creator>
      <dc:date>2020-12-21T16:57:53Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a format from a dataset based off a range of values?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-format-from-a-dataset-based-off-a-range-of-values/m-p/707528#M217248</link>
      <description>&lt;P&gt;Thanks for the response.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to avoid coding in the format as the max and mins change for each combination of the first two variables so i was hoping for an easier way of doing it. I could do&lt;/P&gt;&lt;P&gt;If Category="Y7" and Group="Maths" and score between x and y then rank=0;&lt;/P&gt;&lt;P&gt;and so on, but this feels labour intensive. Do you have any other suggestions?&lt;/P&gt;</description>
      <pubDate>Mon, 21 Dec 2020 16:57:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-format-from-a-dataset-based-off-a-range-of-values/m-p/707528#M217248</guid>
      <dc:creator>denmcl94</dc:creator>
      <dc:date>2020-12-21T16:57:27Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a format from a dataset based off a range of values?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-format-from-a-dataset-based-off-a-range-of-values/m-p/707533#M217251</link>
      <description>&lt;P&gt;This statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if Category="Y7" and Group="Maths" and score between x and y then rank=0;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Is trivial to write from this data:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 input Category $ Group $ Rank Max Min ;
cards;
Y7 Math    1  0 10
Y7 Math    2 10 17
Y8 English 9 45 52
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;With a data step like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename code temp
data _null_;
  set have;
  file code;
  put 'if ' Category= :$quote. 'and ' Group= :$quote. 
      'and score between ' min 'and ' max 'then ' rank= ';'
  ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which you could then use in data step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set new_data ;
%include code ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;PS I corrected the spelling of MATH in your GROUP variable.&amp;nbsp; I have studied many branches of mathematics but only one MATH.&amp;nbsp; Or perhaps I should have change ENGLISH to ENGLISHES instead?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Dec 2020 17:08:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-format-from-a-dataset-based-off-a-range-of-values/m-p/707533#M217251</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-12-21T17:08:39Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a format from a dataset based off a range of values?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-format-from-a-dataset-based-off-a-range-of-values/m-p/707535#M217253</link>
      <description>Thank you very much for this &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13642"&gt;@GertNissen&lt;/a&gt;. I wasn't sure if formats were the best way to do it but your solution was exactly what i'm looking for</description>
      <pubDate>Mon, 21 Dec 2020 17:28:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-format-from-a-dataset-based-off-a-range-of-values/m-p/707535#M217253</guid>
      <dc:creator>denmcl94</dc:creator>
      <dc:date>2020-12-21T17:28:23Z</dc:date>
    </item>
  </channel>
</rss>

