<?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: Multiple variables with CASE in Proc SQL in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Multiple-variables-with-CASE-in-Proc-SQL/m-p/67451#M19294</link>
    <description>Many thanks to both of you.</description>
    <pubDate>Fri, 27 Aug 2010 15:03:37 GMT</pubDate>
    <dc:creator>VD</dc:creator>
    <dc:date>2010-08-27T15:03:37Z</dc:date>
    <item>
      <title>Multiple variables with CASE in Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Multiple-variables-with-CASE-in-Proc-SQL/m-p/67448#M19291</link>
      <description>Is it possible to create more than variable using case in proc sql.&lt;BR /&gt;
&lt;BR /&gt;
For creating one variable, the code (which works fine) is:&lt;BR /&gt;
case&lt;BR /&gt;
when DaysDiff&amp;lt;=10 then '0-10' &lt;BR /&gt;
when 11&amp;lt;=DaysDiff&amp;lt;=20 then '11-20'&lt;BR /&gt;
when 21&amp;lt;=DaysDiff&amp;lt;=30 then '21-30' &lt;BR /&gt;
when 31&amp;lt;=DaysDiff&amp;lt;=40 then '31-40' &lt;BR /&gt;
else 'Greater than 40' &lt;BR /&gt;
end as NumberOfDays &lt;BR /&gt;
 &lt;BR /&gt;
I'm trying to create two variables, with something like this:&lt;BR /&gt;
case&lt;BR /&gt;
when DaysDiff&amp;lt;=10 then '0-10' and '1'&lt;BR /&gt;
when 11&amp;lt;=DaysDiff&amp;lt;=20 then '11-20' and '2'&lt;BR /&gt;
when 21&amp;lt;=DaysDiff&amp;lt;=30 then '21-30' and '3'&lt;BR /&gt;
when 31&amp;lt;=DaysDiff&amp;lt;=40 then '31-40' and '4'&lt;BR /&gt;
else 'Greater than 40' and '5'&lt;BR /&gt;
end as NumberOfDays and NumberOfDaysSequence&lt;BR /&gt;
 &lt;BR /&gt;
The code (and its different variants which I've tried) doesn't work. Is there any way two variables can be created with Case?&lt;BR /&gt;
Thanks.</description>
      <pubDate>Fri, 27 Aug 2010 09:54:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Multiple-variables-with-CASE-in-Proc-SQL/m-p/67448#M19291</guid>
      <dc:creator>VD</dc:creator>
      <dc:date>2010-08-27T09:54:19Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple variables with CASE in Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Multiple-variables-with-CASE-in-Proc-SQL/m-p/67449#M19292</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
I'm not sure if I understand correctly the meaning of your question but I'll try to answer it.&lt;BR /&gt;
&lt;BR /&gt;
Maybe could you combine your Proc SQL with the macro facility ?&lt;BR /&gt;
&lt;BR /&gt;
That way you are able to conditionally add variables to a table:&lt;BR /&gt;
&lt;BR /&gt;
Proc sql;&lt;BR /&gt;
     Create Table MyNewTable as&lt;BR /&gt;
           select a.FirstVariable&lt;BR /&gt;
       %IF (First condition) %THEN %DO; &lt;BR /&gt;
           ,         'ConditionIsTrue'        as SecondVariable&lt;BR /&gt;
       %END; %ELSE %DO;&lt;BR /&gt;
           ,         'ConditionIsFalse'      as ThirdVariable&lt;BR /&gt;
       %END;&lt;BR /&gt;
           ,         'DummyValue'           as LastVariable&lt;BR /&gt;
           from MyOldTable   a;&lt;BR /&gt;
Quit;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
The problem is that this solution is not directly based on the value of other variables of your base table (excepted if you retrieve those values in previous steps by the mean of macro variable i.e...).&lt;BR /&gt;
&lt;BR /&gt;
I hope it helps.&lt;BR /&gt;
&lt;BR /&gt;
Regards,&lt;BR /&gt;
Florent</description>
      <pubDate>Fri, 27 Aug 2010 10:48:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Multiple-variables-with-CASE-in-Proc-SQL/m-p/67449#M19292</guid>
      <dc:creator>Florent</dc:creator>
      <dc:date>2010-08-27T10:48:53Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple variables with CASE in Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Multiple-variables-with-CASE-in-Proc-SQL/m-p/67450#M19293</link>
      <description>VD&lt;BR /&gt;
&lt;BR /&gt;
simply "no".&lt;BR /&gt;
A case construct has one "output", a bit like a macro which generates text, if the text contains no semicolons then it can be invoked many times within a base SAS statement.&lt;BR /&gt;
The "output" of a case construct need not be a column in the output, but it cannot be more than one column, unless you assign it to a column  to which you can refer more than once.&lt;BR /&gt;
An example of where a case construct does not become a column is where that "output" is used in deriving another column as in:&lt;BR /&gt;
   select name, case when age gt 12 then 'teen' else 'pre-teen'&lt;BR /&gt;
                         end !! 'ager' length=15 as life_stage , age&lt;BR /&gt;
      from sashelp.class&lt;BR /&gt;
 &lt;BR /&gt;
I expect you'll find examples more relevant to your situation &lt;BR /&gt;
 &lt;BR /&gt;
I'm not sure, but expect that a case construct could return a value you could use in a where or having clause, &lt;BR /&gt;
Probably reading the documentation would clarify.&lt;BR /&gt;
 &lt;BR /&gt;
luck&lt;BR /&gt;
peterC</description>
      <pubDate>Fri, 27 Aug 2010 11:48:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Multiple-variables-with-CASE-in-Proc-SQL/m-p/67450#M19293</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2010-08-27T11:48:26Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple variables with CASE in Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Multiple-variables-with-CASE-in-Proc-SQL/m-p/67451#M19294</link>
      <description>Many thanks to both of you.</description>
      <pubDate>Fri, 27 Aug 2010 15:03:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Multiple-variables-with-CASE-in-Proc-SQL/m-p/67451#M19294</guid>
      <dc:creator>VD</dc:creator>
      <dc:date>2010-08-27T15:03:37Z</dc:date>
    </item>
  </channel>
</rss>

