<?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: Regarding CASE statement in BASE SAS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Regarding-CASE-statement-in-BASE-SAS/m-p/41713#M8551</link>
    <description>Hi Tim.&lt;BR /&gt;
Thanks for the reply.&lt;BR /&gt;
&lt;BR /&gt;
It will work, no doubt. But due to some reasons, I want to assign the value to the variable through expression only (need to use in SAS ETL) and thats where the problem is.&lt;BR /&gt;
&lt;BR /&gt;
Off course what you have suggested is the final workaround for it; but as long as possible I want to build an expression for a variable where I can evaluate the condition and assign corresponding value.&lt;BR /&gt;
&lt;BR /&gt;
Kapil</description>
    <pubDate>Tue, 26 Aug 2008 12:38:47 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2008-08-26T12:38:47Z</dc:date>
    <item>
      <title>Regarding CASE statement in BASE SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Regarding-CASE-statement-in-BASE-SAS/m-p/41711#M8549</link>
      <description>Hello SAS Gurus,&lt;BR /&gt;
&lt;BR /&gt;
I am using a DATA STEP where I want to write an expression for a variable in my dataset. In that expression, I want to evaluate one condition. If that condition is TRUE, then need to assign &lt;VALUE1&gt; and if its FALSE then another value &lt;VALUE2&gt;.&lt;BR /&gt;
&lt;BR /&gt;
DATA &lt;DATASET1&gt;&lt;BR /&gt;
   SET &lt;DATASET2&gt;&lt;BR /&gt;
   VAR1 = &lt;CONDITION&gt;?if TRUE then &lt;VAL1&gt;: if FALSE then &lt;VAL2&gt;;&lt;BR /&gt;
END;&lt;BR /&gt;
RUN;&lt;BR /&gt;
&lt;BR /&gt;
When searched on SAS help, I got to know about CASE statement where we can write a condition in an expression. But unfortunately its not working and giving some syntax error.&lt;BR /&gt;
&lt;BR /&gt;
NOTE: The JAVA equivalent to such requirement is to use a ternary operator something like this:&lt;BR /&gt;
&lt;BR /&gt;
VAR1= &lt;CONDITION&gt;?&lt;VALUE1&gt; : &lt;VALUE2&gt;&lt;BR /&gt;
&lt;BR /&gt;
Value1 will be assigned to VAR1 if cond2 is true, and value2 in case of FALSE.&lt;BR /&gt;
&lt;BR /&gt;
Need to find the SAS equivalent to the above. &lt;BR /&gt;
Request you to suggest the correct syntax or any other way to achieve the above requirement.&lt;BR /&gt;
&lt;BR /&gt;
Any help regarding this would be highly appreciated.&lt;BR /&gt;
Thanks in Advance.&lt;BR /&gt;
&lt;BR /&gt;
regards&lt;BR /&gt;
Kapil Agrawal&lt;/VALUE2&gt;&lt;/VALUE1&gt;&lt;/CONDITION&gt;&lt;/VAL2&gt;&lt;/VAL1&gt;&lt;/CONDITION&gt;&lt;/DATASET2&gt;&lt;/DATASET1&gt;&lt;/VALUE2&gt;&lt;/VALUE1&gt;</description>
      <pubDate>Tue, 26 Aug 2008 11:46:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Regarding-CASE-statement-in-BASE-SAS/m-p/41711#M8549</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-08-26T11:46:06Z</dc:date>
    </item>
    <item>
      <title>Re: Regarding CASE statement in BASE SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Regarding-CASE-statement-in-BASE-SAS/m-p/41712#M8550</link>
      <description>Kapil,&lt;BR /&gt;
&lt;BR /&gt;
The simplest solution is to use an IF statement:&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
IF &lt;CONDITION&gt; THEN&lt;BR /&gt;
   VAR1 = &lt;VAL1&gt;;&lt;BR /&gt;
ELSE&lt;BR /&gt;
  VAR1 = &lt;VAL2&gt;;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
 Does this meet your needs? The data step language does not have the ?: ternary operator.&lt;/VAL2&gt;&lt;/VAL1&gt;&lt;/CONDITION&gt;</description>
      <pubDate>Tue, 26 Aug 2008 12:16:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Regarding-CASE-statement-in-BASE-SAS/m-p/41712#M8550</guid>
      <dc:creator>Tim_SAS</dc:creator>
      <dc:date>2008-08-26T12:16:22Z</dc:date>
    </item>
    <item>
      <title>Re: Regarding CASE statement in BASE SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Regarding-CASE-statement-in-BASE-SAS/m-p/41713#M8551</link>
      <description>Hi Tim.&lt;BR /&gt;
Thanks for the reply.&lt;BR /&gt;
&lt;BR /&gt;
It will work, no doubt. But due to some reasons, I want to assign the value to the variable through expression only (need to use in SAS ETL) and thats where the problem is.&lt;BR /&gt;
&lt;BR /&gt;
Off course what you have suggested is the final workaround for it; but as long as possible I want to build an expression for a variable where I can evaluate the condition and assign corresponding value.&lt;BR /&gt;
&lt;BR /&gt;
Kapil</description>
      <pubDate>Tue, 26 Aug 2008 12:38:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Regarding-CASE-statement-in-BASE-SAS/m-p/41713#M8551</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-08-26T12:38:47Z</dc:date>
    </item>
    <item>
      <title>Re: Regarding CASE statement in BASE SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Regarding-CASE-statement-in-BASE-SAS/m-p/41714#M8552</link>
      <description>How about the IFC and IFN functions?&lt;BR /&gt;
&lt;BR /&gt;
Here's the 9.1 doc for IFC: &lt;A href="http://support.sas.com/onlinedoc/913/getDoc/en/lrdict.hlp/a002604570.htm" target="_blank"&gt;http://support.sas.com/onlinedoc/913/getDoc/en/lrdict.hlp/a002604570.htm&lt;/A&gt;.</description>
      <pubDate>Tue, 26 Aug 2008 13:38:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Regarding-CASE-statement-in-BASE-SAS/m-p/41714#M8552</guid>
      <dc:creator>Tim_SAS</dc:creator>
      <dc:date>2008-08-26T13:38:42Z</dc:date>
    </item>
    <item>
      <title>Re: Regarding CASE statement in BASE SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Regarding-CASE-statement-in-BASE-SAS/m-p/41715#M8553</link>
      <description>Another way is with an assignment statement (this assigns a 1 for true and a 0 for false):&lt;BR /&gt;
&lt;BR /&gt;
var1 = (&lt;CONDITION&gt;);&lt;BR /&gt;
&lt;BR /&gt;
where &lt;CONDITION&gt; is any logical expression.&lt;BR /&gt;
&lt;BR /&gt;
If all the variables involved in &lt;CONDITION&gt; are numeric, you can extend that and propagate missing values from the variables in &lt;CONDITION&gt;.  Assume &lt;CONDITION&gt; involves VarA, VarB, and VarC, then&lt;BR /&gt;
&lt;BR /&gt;
var1 = (&lt;CONDITION&gt;) + 0*vara*varb*varc;&lt;BR /&gt;
&lt;BR /&gt;
returns 1 for true, 0 for false, and . if any of the condition variables are missing.&lt;BR /&gt;
&lt;BR /&gt;
This works because logical expressions always resolve to 0 or 1 and arithmetic expressions propagate missing values in SAS.&lt;BR /&gt;
&lt;BR /&gt;
Doc Muhlbaier&lt;BR /&gt;
Duke&lt;/CONDITION&gt;&lt;/CONDITION&gt;&lt;/CONDITION&gt;&lt;/CONDITION&gt;&lt;/CONDITION&gt;&lt;/CONDITION&gt;</description>
      <pubDate>Tue, 26 Aug 2008 15:51:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Regarding-CASE-statement-in-BASE-SAS/m-p/41715#M8553</guid>
      <dc:creator>Doc_Duke</dc:creator>
      <dc:date>2008-08-26T15:51:03Z</dc:date>
    </item>
    <item>
      <title>Re: Regarding CASE statement in BASE SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Regarding-CASE-statement-in-BASE-SAS/m-p/41716#M8554</link>
      <description>Bingo!!!!!!!!&lt;BR /&gt;
&lt;BR /&gt;
The IFC function is perfectly working for my requirements &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; . Infact its serving the same wot I was struggling for.&lt;BR /&gt;
&lt;BR /&gt;
Thanks a lot Tim.&lt;BR /&gt;
&lt;BR /&gt;
Really appreciate your knowledge and skills in SAS.&lt;BR /&gt;
&lt;BR /&gt;
Once again thnx for all the help &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;
&lt;BR /&gt;
Kapil</description>
      <pubDate>Wed, 27 Aug 2008 07:28:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Regarding-CASE-statement-in-BASE-SAS/m-p/41716#M8554</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-08-27T07:28:22Z</dc:date>
    </item>
    <item>
      <title>Re: Regarding CASE statement in BASE SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Regarding-CASE-statement-in-BASE-SAS/m-p/41717#M8555</link>
      <description>By the way, I think the CASE statement is specific to PROC SQL and doesn't work in DATA step processing (as you've already discovered).</description>
      <pubDate>Wed, 27 Aug 2008 16:56:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Regarding-CASE-statement-in-BASE-SAS/m-p/41717#M8555</guid>
      <dc:creator>1162</dc:creator>
      <dc:date>2008-08-27T16:56:31Z</dc:date>
    </item>
  </channel>
</rss>

