<?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: if then statement to create new variables of ranges in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/if-then-statement-to-create-new-variables-of-ranges/m-p/331271#M62706</link>
    <description>&lt;P&gt;So it looks like your source data has the age vaues as text instead of numbers. That will make it harder to compare. How about if we convert your 'all' and 'older' (and also 'younger') into extremely low and high values so that we can make a numeric variable out of the ages. &amp;nbsp;Then the logic for telling if the two ranges overlap is pretty simple.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work;
  length text_age1 text_age2 $10 age1 age2 group1-group5 8;
  input text_age1 text_age2;
  if text_age1 in ('younger','all') then age1=-1;
  else age1=input(text_age1,10.);
  if text_age2 in ('older','all') then age2=1000;
  else age2=input(text_age2,10.);
  group1 = (              age1 &amp;lt;= 12) ;
  group2 = (age2 &amp;gt;  12 and age1 &amp;lt;= 60);
  group3 = (age2 &amp;gt;  60 and age1 &amp;lt;=132);
  group4 = (age2 &amp;gt; 132 and age1 &amp;lt;=204);
  group5 = (age2 &amp;gt; 204);
datalines;
13     60
50     70
168   780
0       0
0      240
all     all
192   older
;;;;

proc print; run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 09 Feb 2017 18:40:04 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2017-02-09T18:40:04Z</dc:date>
    <item>
      <title>if then statement to create new variables of ranges</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/if-then-statement-to-create-new-variables-of-ranges/m-p/331069#M62677</link>
      <description>&lt;P&gt;Hi I tried to do this in Excel, but was unsuccessful. Now I need help trying to do this in SAS, please :):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data looks like this (in months---not important)....and Age1 is the beginning of an age range and Age2 is the end.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Age1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Age2&lt;/P&gt;&lt;P&gt;13&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;60 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;---(data collected like this, but basically means that&amp;nbsp;age range is 13-60)&lt;/P&gt;&lt;P&gt;50 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 70&lt;/P&gt;&lt;P&gt;168 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;780&lt;/P&gt;&lt;P&gt;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;240&lt;/P&gt;&lt;P&gt;all &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; all&lt;/P&gt;&lt;P&gt;192 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;older&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to create new variables that are&amp;nbsp;interval groups&amp;nbsp;to see where each age range falls:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Interval groups&amp;nbsp;are:&lt;/P&gt;&lt;P&gt;&amp;lt;12 &amp;nbsp;is group1&lt;/P&gt;&lt;P&gt;12-60 is group2&lt;/P&gt;&lt;P&gt;61-132 is group3&lt;/P&gt;&lt;P&gt;133 - 204 is group4&lt;/P&gt;&lt;P&gt;205 &amp;lt; is group5&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;.....and if "all" in both Age1 and Age2 then they go in all groups&lt;/P&gt;&lt;P&gt;.....and if "0" in both Age1 and Age2 then they go in group1 only&lt;/P&gt;&lt;P&gt;.....and if "older" in Age2 ("older won't be found in Age1), then it goes into the group of where Age1 would fall&amp;nbsp;and all groups after that&lt;/P&gt;&lt;P&gt;.....see that depending on the range (between Age1 and Age2), counts can be in multiple groups&amp;nbsp;(see below)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Data should look like:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Age1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Age2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; group1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;group2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;group3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; group4 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; group5&lt;/P&gt;&lt;P&gt;13 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 60 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0 &amp;nbsp;&amp;lt;-(only falls in group2)&lt;/P&gt;&lt;P&gt;50 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 70 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0 &amp;nbsp;&amp;lt;-(both group2&amp;amp;group3)&lt;/P&gt;&lt;P&gt;168 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;780 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;SPAN&gt;&amp;nbsp;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;1&lt;SPAN&gt;&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;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;240 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;SPAN&gt;&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;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;all &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; all &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;SPAN&gt;&amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; 1 &amp;nbsp;&amp;lt;-(all groups)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;62&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;older &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;SPAN&gt;&amp;nbsp;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp;&amp;lt;-(group3&amp;amp;each one after) &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Any help would be appreciated! Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Thu, 09 Feb 2017 05:33:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/if-then-statement-to-create-new-variables-of-ranges/m-p/331069#M62677</guid>
      <dc:creator>starz4ever2007</dc:creator>
      <dc:date>2017-02-09T05:33:46Z</dc:date>
    </item>
    <item>
      <title>Re: if then statement to create new variables of ranges</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/if-then-statement-to-create-new-variables-of-ranges/m-p/331095#M62680</link>
      <description>&lt;P&gt;Well, as you haven't provided test data in the form of a datastep, this is just untested theory:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  array group{5} 8;
  select;
    when (age1 &amp;lt; 12) group1=1;
    when (12 &amp;lt;= age1 and age2 &amp;lt;=60) group2=1;
    ...
    otherwise;
  end;
run;
&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 Feb 2017 09:02:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/if-then-statement-to-create-new-variables-of-ranges/m-p/331095#M62680</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-02-09T09:02:18Z</dc:date>
    </item>
    <item>
      <title>Re: if then statement to create new variables of ranges</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/if-then-statement-to-create-new-variables-of-ranges/m-p/331229#M62699</link>
      <description>&lt;P&gt;I apologize (here is the test data)&lt;/P&gt;&lt;P&gt;data work;&lt;/P&gt;&lt;P&gt;input age1 age2;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;13&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 60&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;50&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 70&lt;/P&gt;&lt;P&gt;168&amp;nbsp;&amp;nbsp;&amp;nbsp;780&lt;/P&gt;&lt;P&gt;0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&lt;/P&gt;&lt;P&gt;0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;240&lt;/P&gt;&lt;P&gt;all&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; all&lt;/P&gt;&lt;P&gt;192&amp;nbsp;&amp;nbsp;&amp;nbsp;older&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the code you suggested is something I tried as&amp;nbsp;a function&amp;nbsp;in basic Excel before&amp;nbsp;and did not work.&amp;nbsp;The statement......&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;when (12 &amp;lt;= age1 and age2 &amp;lt;=60) group2=1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;would not work as the second row would not get a "1" in group2&amp;nbsp;AND group3&amp;nbsp;even though it should because 50-70 should fall into both groups....&lt;/P&gt;</description>
      <pubDate>Thu, 09 Feb 2017 16:39:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/if-then-statement-to-create-new-variables-of-ranges/m-p/331229#M62699</guid>
      <dc:creator>starz4ever2007</dc:creator>
      <dc:date>2017-02-09T16:39:21Z</dc:date>
    </item>
    <item>
      <title>Re: if then statement to create new variables of ranges</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/if-then-statement-to-create-new-variables-of-ranges/m-p/331236#M62701</link>
      <description>&lt;P&gt;If you run that datastep you will see there are errors as you have number and character (in the input you are reading number as no $). &amp;nbsp;I have removed the invalid data and present:&lt;/P&gt;
&lt;PRE&gt;data work;
  input age1 age2;
datalines;
13     60            
50     70
168   780
0       0
0      240
;
run;

data want;
  set work;
  array group{5} 8;
  group1=ifn(12 &amp;lt;= age1 and age2 &amp;lt;= 60,1,0);
  group2=ifn(61 &amp;lt;= age1 and age2 &amp;lt;= 132,1,0);
  ...
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 Feb 2017 16:53:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/if-then-statement-to-create-new-variables-of-ranges/m-p/331236#M62701</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-02-09T16:53:41Z</dc:date>
    </item>
    <item>
      <title>Re: if then statement to create new variables of ranges</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/if-then-statement-to-create-new-variables-of-ranges/m-p/331271#M62706</link>
      <description>&lt;P&gt;So it looks like your source data has the age vaues as text instead of numbers. That will make it harder to compare. How about if we convert your 'all' and 'older' (and also 'younger') into extremely low and high values so that we can make a numeric variable out of the ages. &amp;nbsp;Then the logic for telling if the two ranges overlap is pretty simple.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work;
  length text_age1 text_age2 $10 age1 age2 group1-group5 8;
  input text_age1 text_age2;
  if text_age1 in ('younger','all') then age1=-1;
  else age1=input(text_age1,10.);
  if text_age2 in ('older','all') then age2=1000;
  else age2=input(text_age2,10.);
  group1 = (              age1 &amp;lt;= 12) ;
  group2 = (age2 &amp;gt;  12 and age1 &amp;lt;= 60);
  group3 = (age2 &amp;gt;  60 and age1 &amp;lt;=132);
  group4 = (age2 &amp;gt; 132 and age1 &amp;lt;=204);
  group5 = (age2 &amp;gt; 204);
datalines;
13     60
50     70
168   780
0       0
0      240
all     all
192   older
;;;;

proc print; run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 Feb 2017 18:40:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/if-then-statement-to-create-new-variables-of-ranges/m-p/331271#M62706</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-02-09T18:40:04Z</dc:date>
    </item>
    <item>
      <title>Re: if then statement to create new variables of ranges</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/if-then-statement-to-create-new-variables-of-ranges/m-p/627040#M77491</link>
      <description>&lt;P&gt;I also am having the same problem and do not understand how to it.&amp;nbsp; I am trying to use the bg variable which is blood glucose lvl.&amp;nbsp; I want the normal type to be 70-105 bg and abnormal to be all other numbers.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data wb_bg ;&lt;BR /&gt;SET wb_bg_1 wb_bg_2 ;&lt;BR /&gt;DC= '28jun02' ;&lt;BR /&gt;TC= '08:40' ;&lt;BR /&gt;DOW=weekday(date);&lt;BR /&gt;if 70&amp;lt;- bg &amp;lt;-105 then Type= 'A' ;&lt;BR /&gt;else if bg= 70-105 then Type= 'N' ;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc format ;&lt;BR /&gt;value DOW 1= 'Sun' 2='Mon' 3='Tue' 4='Wed' 5= 'Thu' 6= 'Fri' 7= 'Sat' ;&lt;BR /&gt;value Type 'A'= 'Abnormal' 'N'= 'Normal' ;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc print data=wb_bg;&lt;BR /&gt;format Date date7. Time time5. DOW DOW. Type Type.;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Feb 2020 21:11:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/if-then-statement-to-create-new-variables-of-ranges/m-p/627040#M77491</guid>
      <dc:creator>gracynnrose</dc:creator>
      <dc:date>2020-02-24T21:11:04Z</dc:date>
    </item>
    <item>
      <title>Re: if then statement to create new variables of ranges</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/if-then-statement-to-create-new-variables-of-ranges/m-p/627044#M77492</link>
      <description>&lt;PRE&gt;if 70&amp;lt;- bg &amp;lt;-105 then Type= 'A' ;&lt;/PRE&gt;
&lt;P&gt;I don't think this is what you really want to type ... this means if -bg is between 70 and -105 then TYPE='A'; Then you type&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;if bg= 70-105 then Type= 'N' ;&lt;/PRE&gt;
&lt;P&gt;Since 70-105 is -35, then this is the same as&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if bg= -35 then type='N';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which probably isn't what you want either.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;While it's not clear to me exactly what you do want, maybe something like this would work&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format ;
value DOW 1= 'Sun' 2='Mon' 3='Tue' 4='Wed' 5= 'Thu' 6= 'Fri' 7= 'Sat' ;
value Type 70-105='Normal' other= 'Abnormal';
run;

data wb_bg;
     set wb_bg_1 wb_bg_2;
    dc='28jun02'd;
    tc='08:40't;
    dow=weekday(date);
    format bg type. dow dow.;
run;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Feb 2020 21:24:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/if-then-statement-to-create-new-variables-of-ranges/m-p/627044#M77492</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-02-24T21:24:56Z</dc:date>
    </item>
  </channel>
</rss>

