<?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: select when in data set in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/select-when-in-data-set/m-p/601504#M173994</link>
    <description>&lt;P&gt;For single variable ranges I find formats easier in most cases:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc format library=work;
   value X_ind;
   0 = '0'
   1,2,3 = '1-3'
   4,5,6 = '4-6'
   7,8,9,10='7-10'
   10&amp;lt;-100 ='10-100'
   100&amp;lt;-high= '100+'
   ;
run;

Proc print data=tbl1;
   var x;
   format x x_ind. ;
run;&lt;/PRE&gt;
&lt;P&gt;The select becomes much more useful when you have multiple things to do for each group of values or when another , or more, variables are needed to complete the recode.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Generally you would only use BETWEEN in Proc SQL not a data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use syntax like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;when (10 &amp;lt; x &amp;lt;=100)&lt;/PRE&gt;
&lt;P&gt;which has the minor advantage of better readability than placing AND between the upper and lower range.&lt;/P&gt;</description>
    <pubDate>Mon, 04 Nov 2019 20:28:44 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2019-11-04T20:28:44Z</dc:date>
    <item>
      <title>select when in data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/select-when-in-data-set/m-p/601327#M173916</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I am using select when in data set (I know that I can do it easily with IF but I wan to learn it ).&lt;/P&gt;
&lt;P&gt;There is an error with "&lt;CODE class=" language-sas"&gt;when(between 11 and 100) Ind='10-100';"&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;What is the correct way to write it please?&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;The error is&lt;/CODE&gt;&lt;/P&gt;
&lt;P&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;&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;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 22&lt;/P&gt;
&lt;P&gt;ERROR 22-322: Syntax error, expecting one of the following: !, !!, &amp;amp;, (, *, **, +, ',', -, /, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;&amp;lt;, &amp;gt;=, AND, EQ, GE,&lt;/P&gt;
&lt;P&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;&amp;nbsp;GT, LE, LT, MAX, MIN, NE, NG, NL, OR, [, ^=, {, |, ||, ~=.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data tbl2;
set tbl1;
length Ind $10;
select(X);
     when(0)Ind='0';
     when(1,2,3) Ind='1-3';
     when(4,5,6)Ind='4-6';
     when(7,8,9,10)Ind='7-10';
     when(between 11 and 100) Ind='10-100';
     otherwise Ind='100+';
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 04 Nov 2019 09:57:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/select-when-in-data-set/m-p/601327#M173916</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2019-11-04T09:57:39Z</dc:date>
    </item>
    <item>
      <title>Re: select when in data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/select-when-in-data-set/m-p/601337#M173924</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"Between " is seems to be not available. Instead use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;when(x &amp;gt; 10 and x &amp;lt;= 100) Ind='10-100';&lt;/P&gt;</description>
      <pubDate>Mon, 04 Nov 2019 10:39:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/select-when-in-data-set/m-p/601337#M173924</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2019-11-04T10:39:12Z</dc:date>
    </item>
    <item>
      <title>Re: select when in data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/select-when-in-data-set/m-p/601504#M173994</link>
      <description>&lt;P&gt;For single variable ranges I find formats easier in most cases:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc format library=work;
   value X_ind;
   0 = '0'
   1,2,3 = '1-3'
   4,5,6 = '4-6'
   7,8,9,10='7-10'
   10&amp;lt;-100 ='10-100'
   100&amp;lt;-high= '100+'
   ;
run;

Proc print data=tbl1;
   var x;
   format x x_ind. ;
run;&lt;/PRE&gt;
&lt;P&gt;The select becomes much more useful when you have multiple things to do for each group of values or when another , or more, variables are needed to complete the recode.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Generally you would only use BETWEEN in Proc SQL not a data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use syntax like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;when (10 &amp;lt; x &amp;lt;=100)&lt;/PRE&gt;
&lt;P&gt;which has the minor advantage of better readability than placing AND between the upper and lower range.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Nov 2019 20:28:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/select-when-in-data-set/m-p/601504#M173994</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-11-04T20:28:44Z</dc:date>
    </item>
  </channel>
</rss>

