<?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 Can someone please help me find the right way to set up the criteria in 'Case when' ? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Can-someone-please-help-me-find-the-right-way-to-set-up-the/m-p/721161#M223462</link>
    <description>&lt;P&gt;Hey-&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to use a 'case when' to categorize the right billcodes, for example, code 'A100', 'A101', 'A102', ..., 'A199' need to be put under 'Category 1'.&lt;/P&gt;&lt;P&gt;however I want to find a short way using&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;case when billcode in &lt;STRONG&gt;('A100', 'A101', 'A102', ..., 'A199' )&lt;/STRONG&gt; then 'Category 1'&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I dont want to list 100 codes separately in the above parenthesis,&amp;nbsp;do you know if there is a good/short way of doing that?&lt;/P&gt;&lt;P&gt;Greatly appreciate!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 23 Feb 2021 01:56:31 GMT</pubDate>
    <dc:creator>LightJade</dc:creator>
    <dc:date>2021-02-23T01:56:31Z</dc:date>
    <item>
      <title>Can someone please help me find the right way to set up the criteria in 'Case when' ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-someone-please-help-me-find-the-right-way-to-set-up-the/m-p/721161#M223462</link>
      <description>&lt;P&gt;Hey-&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to use a 'case when' to categorize the right billcodes, for example, code 'A100', 'A101', 'A102', ..., 'A199' need to be put under 'Category 1'.&lt;/P&gt;&lt;P&gt;however I want to find a short way using&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;case when billcode in &lt;STRONG&gt;('A100', 'A101', 'A102', ..., 'A199' )&lt;/STRONG&gt; then 'Category 1'&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I dont want to list 100 codes separately in the above parenthesis,&amp;nbsp;do you know if there is a good/short way of doing that?&lt;/P&gt;&lt;P&gt;Greatly appreciate!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2021 01:56:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-someone-please-help-me-find-the-right-way-to-set-up-the/m-p/721161#M223462</guid>
      <dc:creator>LightJade</dc:creator>
      <dc:date>2021-02-23T01:56:31Z</dc:date>
    </item>
    <item>
      <title>Re: Can someone please help me find the right way to set up the criteria in 'Case when' ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-someone-please-help-me-find-the-right-way-to-set-up-the/m-p/721162#M223463</link>
      <description>&lt;P&gt;Like this perhaps?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;case when billcode =: 'A1' then 'Category 1'&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Assuming all values starting with A1 should be selected.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2021 02:03:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-someone-please-help-me-find-the-right-way-to-set-up-the/m-p/721162#M223463</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2021-02-23T02:03:02Z</dc:date>
    </item>
    <item>
      <title>Re: Can someone please help me find the right way to set up the criteria in 'Case when' ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-someone-please-help-me-find-the-right-way-to-set-up-the/m-p/721163#M223464</link>
      <description>thank you. but what if I have&lt;BR /&gt;&lt;BR /&gt;case when billcode in ('A100', 'A101', 'A102', ..., 'A158' ) then 'Category 1'&lt;BR /&gt;&lt;BR /&gt;thank you!</description>
      <pubDate>Tue, 23 Feb 2021 02:06:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-someone-please-help-me-find-the-right-way-to-set-up-the/m-p/721163#M223464</guid>
      <dc:creator>LightJade</dc:creator>
      <dc:date>2021-02-23T02:06:14Z</dc:date>
    </item>
    <item>
      <title>Re: Can someone please help me find the right way to set up the criteria in 'Case when' ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-someone-please-help-me-find-the-right-way-to-set-up-the/m-p/721164#M223465</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;case when billcode in: ('A10', 'A11','A12','A13','A14','A151','A152','A153','A154','A155','A156','A157','A158') then 'Category 1'&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 Feb 2021 02:14:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-someone-please-help-me-find-the-right-way-to-set-up-the/m-p/721164#M223465</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2021-02-23T02:14:27Z</dc:date>
    </item>
    <item>
      <title>Re: Can someone please help me find the right way to set up the criteria in 'Case when' ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-someone-please-help-me-find-the-right-way-to-set-up-the/m-p/721165#M223466</link>
      <description>&lt;P&gt;thank you. I am using SAS 9, it looks like my SAS cannot recognize the ' &lt;STRONG&gt;:&lt;/STRONG&gt; ' in the code, it give error msg&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: (, SELECT.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you know any other way of doing this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2021 02:29:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-someone-please-help-me-find-the-right-way-to-set-up-the/m-p/721165#M223466</guid>
      <dc:creator>LightJade</dc:creator>
      <dc:date>2021-02-23T02:29:05Z</dc:date>
    </item>
    <item>
      <title>Re: Can someone please help me find the right way to set up the criteria in 'Case when' ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-someone-please-help-me-find-the-right-way-to-set-up-the/m-p/721169#M223469</link>
      <description>&lt;P&gt;I wouldn't call below the best approach but it will create a macro variable which will list the CASE Expression values:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro list_codes;

%macro _;
%mend _;

%global var;

data a;
	do i  = 100 to 199;
		var = cats("'","A",i,"'");
		output;
	end;
run;

proc sql noprint;
	select var
		into :var separated by ","
			from a;
quit;

proc datasets lib=work nodetails nolist;
	delete a;
run;

quit;

%mend;

/* Test */
data s;
	var = 'A100';
run;

proc sql;
	create table want as
		select *,
			case 
				when var in (&amp;amp;var.) then 'Category 1'
				else 'Category 2' 
			end 
		as cat
			from s;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 Feb 2021 02:39:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-someone-please-help-me-find-the-right-way-to-set-up-the/m-p/721169#M223469</guid>
      <dc:creator>qoit</dc:creator>
      <dc:date>2021-02-23T02:39:27Z</dc:date>
    </item>
    <item>
      <title>Re: Can someone please help me find the right way to set up the criteria in 'Case when' ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-someone-please-help-me-find-the-right-way-to-set-up-the/m-p/721176#M223474</link>
      <description>&lt;P&gt;Please post the complete SAS log of your SQL program.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2021 03:02:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-someone-please-help-me-find-the-right-way-to-set-up-the/m-p/721176#M223474</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2021-02-23T03:02:23Z</dc:date>
    </item>
    <item>
      <title>Re: Can someone please help me find the right way to set up the criteria in 'Case when' ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-someone-please-help-me-find-the-right-way-to-set-up-the/m-p/721177#M223475</link>
      <description>&lt;P&gt;This partial solution should work:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;case when substr(billcode,1,3) in ('A10', 'A11','A12','A13','A14') then 'Category 1'&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 Feb 2021 03:20:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-someone-please-help-me-find-the-right-way-to-set-up-the/m-p/721177#M223475</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2021-02-23T03:20:11Z</dc:date>
    </item>
    <item>
      <title>Re: Can someone please help me find the right way to set up the criteria in 'Case when' ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-someone-please-help-me-find-the-right-way-to-set-up-the/m-p/721243#M223520</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/347781"&gt;@LightJade&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It looks like you're using SQL. The below code creates A1, A2,..., A200 and then applies the rule you want (as I understand it).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you need a different outcome then please provide the output you need based on some given input.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* set up data A1, A2, ..., A199, A200 */
data have;
   do i = 1 to 200;
      billcode = cats('A',i);
      output;
   end;
run;


/* ignore 'A' and then test number */
proc sql noprint;
   create table
      want
   as select
      billcode
     ,case
         when input(substr(billcode,2),8.) between 100 and 158
         then 'Category 1'
         else 'Category 0'
      end as category
   from
      have
   ;
quit;
&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;Kind regards,&lt;/P&gt;
&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2021 11:13:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-someone-please-help-me-find-the-right-way-to-set-up-the/m-p/721243#M223520</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2021-02-23T11:13:57Z</dc:date>
    </item>
    <item>
      <title>Re: Can someone please help me find the right way to set up the criteria in 'Case when' ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-someone-please-help-me-find-the-right-way-to-set-up-the/m-p/721247#M223522</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/347781"&gt;@LightJade&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;thank you. but what if I have&lt;BR /&gt;&lt;BR /&gt;case when billcode in ('A100', 'A101', 'A102', ..., 'A158' ) then 'Category 1'&lt;BR /&gt;&lt;BR /&gt;thank you!&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I would solve such issues with a custom format:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data cntlin_ds;
fmtname = "billcode";
type = "C";
label = "category 1";
do i = 1 to 158;
  start = "A" !! put(i,z3.);
  output;
end;
run;

proc format cntlin=cntlin_ds;
run;

proc sql;
create table want as
  select
    put(billcode,$billcode.) as newvar
  from have
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Expand the first data step to cover other ranges, and possibly add one observation for "other" with hlo = "O".&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2021 11:50:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-someone-please-help-me-find-the-right-way-to-set-up-the/m-p/721247#M223522</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-02-23T11:50:35Z</dc:date>
    </item>
  </channel>
</rss>

