<?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: Recode using ranges in data step? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Recode-using-ranges-in-data-step/m-p/365833#M275152</link>
    <description>&lt;P&gt;One way is to not add any variables an use your existing data set and assign a format to the variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc format;&lt;/P&gt;
&lt;P&gt;value agegrp&lt;/P&gt;
&lt;P&gt;1 - 24 = '1'&lt;/P&gt;
&lt;P&gt;25 - 54= '2'&lt;/P&gt;
&lt;P&gt;55 - high='3';&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc freq data=have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; tables age;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;format age agegrp.;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The format will create the group for the counts as well as changing displayed value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your code is not correct, use the colon : to indicate a numeric range with the IN operator&lt;/P&gt;
&lt;P&gt;if age in (15:24) then &amp;nbsp;agegroup=1;&lt;/P&gt;
&lt;P&gt;else if age in (25:54) then agegroup=2;&lt;/P&gt;
&lt;P&gt;else if age &amp;gt;= 55 then agegroup=3;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 09 Jun 2017 20:58:59 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2017-06-09T20:58:59Z</dc:date>
    <item>
      <title>Recode using ranges in data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recode-using-ranges-in-data-step/m-p/365830#M275151</link>
      <description>&lt;P&gt;I'm trying to recode&amp;nbsp;age into groups but this is not working (just&amp;nbsp;takes the first number in the bracket, from what I can tell)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data new;&lt;/P&gt;&lt;P&gt;set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if age in (15-24) then &amp;nbsp;agegroup=1;&lt;/P&gt;&lt;P&gt;else if age in (25-54) then agegroup=2;&lt;/P&gt;&lt;P&gt;else if age &amp;gt;= 55 then agegroup=3;&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;What is the proper way to do this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Edit: Also I know one can do it&amp;nbsp;the way below, but it is very tedious, especially when there are more than 3&amp;nbsp;values being made. I'm looking for something easier, with ranges:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;IF &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/FONT&gt;&lt;FONT face="Courier New" color="teal"&gt;&lt;STRONG&gt;15&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&amp;lt;= age_tabs &amp;lt;=&amp;nbsp; &lt;/FONT&gt;&lt;FONT face="Courier New" color="teal"&gt;&lt;STRONG&gt;24&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;then&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; agegroup_main = &lt;/FONT&gt;&lt;FONT face="Courier New" color="teal"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;else if&amp;nbsp; &lt;/FONT&gt;&lt;FONT face="Courier New" color="teal"&gt;&lt;STRONG&gt;25&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&amp;lt;= age_tabs &amp;lt;=&amp;nbsp; &lt;/FONT&gt;&lt;FONT face="Courier New" color="teal"&gt;&lt;STRONG&gt;54&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;then&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; agegroup_main =&lt;/FONT&gt;&lt;FONT face="Courier New" color="teal"&gt;&lt;STRONG&gt;2&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;else if &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; age_tabs &amp;gt;=&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;FONT face="Courier New" color="teal"&gt;&lt;STRONG&gt;55&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;then&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; agegroup_main =&lt;/FONT&gt;&lt;FONT face="Courier New" color="teal"&gt;&lt;STRONG&gt;3&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;else &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;agegroup_main = &lt;/FONT&gt;&lt;FONT face="Courier New" color="teal"&gt;&lt;STRONG&gt;.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 09 Jun 2017 20:55:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recode-using-ranges-in-data-step/m-p/365830#M275151</guid>
      <dc:creator>fieldsa83</dc:creator>
      <dc:date>2017-06-09T20:55:47Z</dc:date>
    </item>
    <item>
      <title>Re: Recode using ranges in data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recode-using-ranges-in-data-step/m-p/365833#M275152</link>
      <description>&lt;P&gt;One way is to not add any variables an use your existing data set and assign a format to the variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc format;&lt;/P&gt;
&lt;P&gt;value agegrp&lt;/P&gt;
&lt;P&gt;1 - 24 = '1'&lt;/P&gt;
&lt;P&gt;25 - 54= '2'&lt;/P&gt;
&lt;P&gt;55 - high='3';&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc freq data=have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; tables age;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;format age agegrp.;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The format will create the group for the counts as well as changing displayed value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your code is not correct, use the colon : to indicate a numeric range with the IN operator&lt;/P&gt;
&lt;P&gt;if age in (15:24) then &amp;nbsp;agegroup=1;&lt;/P&gt;
&lt;P&gt;else if age in (25:54) then agegroup=2;&lt;/P&gt;
&lt;P&gt;else if age &amp;gt;= 55 then agegroup=3;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2017 20:58:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recode-using-ranges-in-data-step/m-p/365833#M275152</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-06-09T20:58:59Z</dc:date>
    </item>
  </channel>
</rss>

