<?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 case when statement in proc sql sas in SAS Studio</title>
    <link>https://communities.sas.com/t5/SAS-Studio/select-case-when-statement-in-proc-sql-sas/m-p/553663#M7464</link>
    <description>&lt;P&gt;Heartily agree with &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15475"&gt;@andreas_lds&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One of the strong features of SAS is the concept of a display format. You can do multiple types of analysis on groups based on formats without adding lots of extra variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Using a format in the SASHELP.CLASS data set we could also provide groups of over/under a single age (creating 2 groups), or 4.&lt;/P&gt;
&lt;P&gt;With the MULTILABEL format option, though only useable directly my a few procedures such as Proc means, Tabulate and Report, you can even create nested groups.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also you can apply the same format to multiple variables. So suppose you had other variables that you wanted to analyze with the same boundary values such as "planned spending" or "last year amount". Apply the same format to those variables. Otherwise you have to rewrite the same code for each variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With numeric values you can have the numeric value order control appearance in procedures. With your example the default sort order and the appearance order in many procedures would be "above 200" , "below 100" then "between 100 to 200". Which is somewhat odd in most senses.&lt;/P&gt;</description>
    <pubDate>Wed, 24 Apr 2019 14:57:18 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2019-04-24T14:57:18Z</dc:date>
    <item>
      <title>select case when statement in proc sql sas</title>
      <link>https://communities.sas.com/t5/SAS-Studio/select-case-when-statement-in-proc-sql-sas/m-p/553524#M7454</link>
      <description>&lt;P&gt;Hi&amp;nbsp; Team,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In attached file I want to categorize the respondent into three category based on their spending(below 100,100-200 and above 200&lt;/P&gt;&lt;P&gt;) and how we count the number of unique customer in each group.&lt;/P&gt;&lt;P&gt;however I have tried below codes but not successful to finding the result-&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table new as&lt;BR /&gt;select&lt;BR /&gt;case&lt;BR /&gt;when amtspent &amp;gt; 100 then "below 100"&lt;BR /&gt;when amtspent 100-200 then "between100 to 200"&lt;BR /&gt;when amtspent &amp;lt; 200 then "above 200"&lt;BR /&gt;else&lt;BR /&gt;value "nothing";&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kindly check and advise.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Manoj Ahuja&lt;/P&gt;</description>
      <pubDate>Wed, 24 Apr 2019 05:50:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/select-case-when-statement-in-proc-sql-sas/m-p/553524#M7454</guid>
      <dc:creator>Manojahuja1418</dc:creator>
      <dc:date>2019-04-24T05:50:25Z</dc:date>
    </item>
    <item>
      <title>Re: select case when statement in proc sql sas</title>
      <link>https://communities.sas.com/t5/SAS-Studio/select-case-when-statement-in-proc-sql-sas/m-p/553528#M7456</link>
      <description>&lt;P&gt;Using case for such tasks is possible, but not recommended. Using a self-defined format is the way to go. The following code uses sashelp.class and the age-variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
   value Age
      LOW -&amp;lt; 12 = 'under 12'
      12-14 = '12-14'
      14 &amp;lt;- HIGH = 'above 14'
   ;
run;

proc summary data=sashelp.class nway;
   class Age;
   format Age Age.;
   output out=countAgeGroup(drop=_type_ rename=(_freq_=count));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Apr 2019 06:02:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/select-case-when-statement-in-proc-sql-sas/m-p/553528#M7456</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-04-24T06:02:20Z</dc:date>
    </item>
    <item>
      <title>Re: select case when statement in proc sql sas</title>
      <link>https://communities.sas.com/t5/SAS-Studio/select-case-when-statement-in-proc-sql-sas/m-p/553663#M7464</link>
      <description>&lt;P&gt;Heartily agree with &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15475"&gt;@andreas_lds&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One of the strong features of SAS is the concept of a display format. You can do multiple types of analysis on groups based on formats without adding lots of extra variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Using a format in the SASHELP.CLASS data set we could also provide groups of over/under a single age (creating 2 groups), or 4.&lt;/P&gt;
&lt;P&gt;With the MULTILABEL format option, though only useable directly my a few procedures such as Proc means, Tabulate and Report, you can even create nested groups.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also you can apply the same format to multiple variables. So suppose you had other variables that you wanted to analyze with the same boundary values such as "planned spending" or "last year amount". Apply the same format to those variables. Otherwise you have to rewrite the same code for each variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With numeric values you can have the numeric value order control appearance in procedures. With your example the default sort order and the appearance order in many procedures would be "above 200" , "below 100" then "between 100 to 200". Which is somewhat odd in most senses.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Apr 2019 14:57:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/select-case-when-statement-in-proc-sql-sas/m-p/553663#M7464</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-04-24T14:57:18Z</dc:date>
    </item>
    <item>
      <title>Re: select case when statement in proc sql sas</title>
      <link>https://communities.sas.com/t5/SAS-Studio/select-case-when-statement-in-proc-sql-sas/m-p/553669#M7465</link>
      <description>&lt;P&gt;REMOVE the VALUE keyword from the ELSE clause of your CASE.&lt;/P&gt;
&lt;P&gt;Use valid boolean logic in the WHEN clauses&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;case
when amtspent &amp;gt; 100 then "below 100"
when 100&amp;lt;= amtspent &amp;lt;=200 then "between100 to 200"
when amtspent &amp;gt; 200 then "above 200"
else "nothing"
end&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;REMOVE the extra semi-colons in the middle of your CREATE statement.&lt;/P&gt;
&lt;P&gt;Give your new variable that the CASE is generating a name.&lt;/P&gt;
&lt;P&gt;ADD a FROM clause so SQL knows what you are selecting from.&lt;/P&gt;
&lt;P&gt;SQL does not need RUN statement. Each statement runs immediately. Use QUIT statement to end the PROC SQL step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table new as
  select 
    *
   ,case
      when amtspent &amp;gt; 100 then "below 100"
      when 100&amp;lt;= amtspent &amp;lt;=200 then "between100 to 200"
      when amtspent &amp;gt; 200 then "above 200"
      else "nothing"
    end as new_var
  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;</description>
      <pubDate>Wed, 24 Apr 2019 15:12:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/select-case-when-statement-in-proc-sql-sas/m-p/553669#M7465</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-04-24T15:12:19Z</dc:date>
    </item>
  </channel>
</rss>

