<?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: How to use macro %if %then; %else;? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-macro-if-then-else/m-p/368955#M88004</link>
    <description>&lt;P&gt;The macro language processor applies %EVAL to all %IF conditions. &amp;nbsp;In this case, I would guess that the value for &amp;amp;PctSmokers contains a decimal point, and %EVAL can't handle a decimal point. &amp;nbsp;But a slightly different function can. &amp;nbsp;Switch to:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="p1"&gt;&lt;SPAN class="s3"&gt;%if&lt;/SPAN&gt;&amp;nbsp;%sysevalf(&amp;amp;PctSmokers &amp;gt; &lt;SPAN class="s4"&gt;&lt;STRONG&gt;35)&lt;/STRONG&gt;&lt;/SPAN&gt; &lt;SPAN class="s3"&gt;%then&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class="p1"&gt;&lt;SPAN class="s3"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;%do&lt;/SPAN&gt;;&lt;/P&gt;
&lt;P class="p1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="p1"&gt;The parentheses really are in the proper place here.&lt;/P&gt;</description>
    <pubDate>Tue, 20 Jun 2017 21:31:41 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2017-06-20T21:31:41Z</dc:date>
    <item>
      <title>How to use macro %if %then; %else;?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-macro-if-then-else/m-p/368953#M88003</link>
      <description>&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;Hello,&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;I'm trying to use macro&amp;nbsp;%if %then; %else; for a numeric operand, and I'd appreciate if anyone could let me know how to do it. I would like to create a&amp;nbsp;new variable named "status" to indicate whether it is "serious" or "moderate."&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt;&lt;/SPAN&gt; Serious_Smoker(serious) /store;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s3"&gt;&amp;nbsp; &amp;nbsp;%let&lt;/SPAN&gt; Serious_Smoker = &lt;SPAN class="s3"&gt;%upcase&lt;/SPAN&gt;(&amp;amp;serious);&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s3"&gt;&amp;nbsp; &amp;nbsp;%if&lt;/SPAN&gt; &amp;amp;PctSmokers &amp;gt; &lt;SPAN class="s4"&gt;&lt;STRONG&gt;35&lt;/STRONG&gt;&lt;/SPAN&gt; &lt;SPAN class="s3"&gt;%then&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s3"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;%do&lt;/SPAN&gt;;&lt;/P&gt;&lt;P class="p2"&gt;&lt;SPAN class="s5"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; title &lt;/SPAN&gt;'Results for Serious Smoker Population (&amp;gt;35%)'&lt;SPAN class="s5"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p2"&gt;&lt;SPAN class="s5"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Status = "Serious";&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;run;&lt;/P&gt;&lt;P class="p3"&gt;&amp;nbsp; &amp;nbsp;%end&lt;SPAN class="s5"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p3"&gt;&amp;nbsp; &amp;nbsp;%else&lt;/P&gt;&lt;P class="p3"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;%do&lt;SPAN class="s5"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p2"&gt;&lt;SPAN class="s5"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; title &lt;/SPAN&gt;'Results for Moderate Smoker Population (&amp;lt;=35%)'&lt;SPAN class="s5"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p2"&gt;&lt;SPAN class="s5"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Status = "Moderate";&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;run;&lt;/P&gt;&lt;P class="p3"&gt;%end&lt;SPAN class="s5"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;&lt;STRONG&gt;%mend&lt;/STRONG&gt;&lt;/SPAN&gt; Serious_Smoker;&lt;/P&gt;&lt;P class="p1"&gt;%&lt;STRONG&gt;&lt;I&gt;Serious_Smoker&lt;/I&gt;&lt;/STRONG&gt;;&lt;/P&gt;&lt;P class="p1"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p1"&gt;I got error messages:&amp;nbsp;&lt;/P&gt;&lt;P class="p1"&gt;ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;operand is required. The condition was: &amp;amp;PctSmokers &amp;gt; 35&lt;/P&gt;&lt;P class="p1"&gt;ERROR: The macro SERIOUS_SMOKER will stop executing.&lt;/P&gt;&lt;P class="p1"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p1"&gt;--&lt;/P&gt;&lt;P class="p1"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p1"&gt;Thank you very much for your help in advance!&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jun 2017 21:27:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-macro-if-then-else/m-p/368953#M88003</guid>
      <dc:creator>cwpark</dc:creator>
      <dc:date>2017-06-20T21:27:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to use macro %if %then; %else;?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-macro-if-then-else/m-p/368955#M88004</link>
      <description>&lt;P&gt;The macro language processor applies %EVAL to all %IF conditions. &amp;nbsp;In this case, I would guess that the value for &amp;amp;PctSmokers contains a decimal point, and %EVAL can't handle a decimal point. &amp;nbsp;But a slightly different function can. &amp;nbsp;Switch to:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="p1"&gt;&lt;SPAN class="s3"&gt;%if&lt;/SPAN&gt;&amp;nbsp;%sysevalf(&amp;amp;PctSmokers &amp;gt; &lt;SPAN class="s4"&gt;&lt;STRONG&gt;35)&lt;/STRONG&gt;&lt;/SPAN&gt; &lt;SPAN class="s3"&gt;%then&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class="p1"&gt;&lt;SPAN class="s3"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;%do&lt;/SPAN&gt;;&lt;/P&gt;
&lt;P class="p1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="p1"&gt;The parentheses really are in the proper place here.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jun 2017 21:31:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-macro-if-then-else/m-p/368955#M88004</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-06-20T21:31:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to use macro %if %then; %else;?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-macro-if-then-else/m-p/368961#M88008</link>
      <description>&lt;P&gt;I have a number of questions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your macro only has one parameter (i.e., serious), but when you call the macro you don't provide a value for the macro variable SERIOUS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then, in your macro, you check to see if&amp;nbsp;&lt;SPAN&gt;&amp;amp;PctSmokers is greater than 35. Where did you declare that macro variable?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Third, you have a line of code that sets the value of a non-macro variable called SERIOUS. That code would only work if it is called from within a data step.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Art, CEO, AnalystFinder.com&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jun 2017 21:54:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-macro-if-then-else/m-p/368961#M88008</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-06-20T21:54:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to use macro %if %then; %else;?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-macro-if-then-else/m-p/368988#M88013</link>
      <description>&lt;P&gt;Thank you for your reply. PctSmokers are continuous variable that has no decimal points.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The number of dataset that I input are three: PctSmokers (continuous), income (categorical), and age (categorical).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In addition to that, I would like to add "Status" variable in the macro "if then" statements. I think I need a numeric operand for local macro variable "serious" and also need to figure out how to create "Status" variable.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I seprately display &amp;gt;35% and &amp;lt;=35% smoker population?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Jun 2017 01:40:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-macro-if-then-else/m-p/368988#M88013</guid>
      <dc:creator>cwpark</dc:creator>
      <dc:date>2017-06-21T01:40:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to use macro %if %then; %else;?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-macro-if-then-else/m-p/368991#M88016</link>
      <description>&lt;P&gt;Thanks for your help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I set 'serious' as a local macro variable. There are three variable in the original dataset: PctSmokers, income, and age. Depending on PctSmokers, I'd want to see two divided results: serious smoker population vs moderate smoker population, by using %if %then macro statement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think I need to use a function for numeric operand, not "upcase," and I'm figuring out what it is.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Jun 2017 01:45:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-macro-if-then-else/m-p/368991#M88016</guid>
      <dc:creator>cwpark</dc:creator>
      <dc:date>2017-06-21T01:45:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to use macro %if %then; %else;?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-macro-if-then-else/m-p/368992#M88017</link>
      <description>&lt;P&gt;It would help if you provide some example datasets, all of your code, and a brief explanation of what you are trying to do. A macro may not even be needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Jun 2017 01:47:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-macro-if-then-else/m-p/368992#M88017</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-06-21T01:47:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to use macro %if %then; %else;?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-macro-if-then-else/m-p/368993#M88018</link>
      <description>&lt;P&gt;The dataset example is:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data smoker;&lt;BR /&gt;input PctSmokers Income $ Age $;&amp;nbsp;&lt;BR /&gt;datalines;&amp;nbsp;&lt;BR /&gt;45 1 1&lt;BR /&gt;35 2&amp;nbsp;2&lt;BR /&gt;14 5 3&lt;BR /&gt;27 1&amp;nbsp;1&lt;BR /&gt;20 2 2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd want to see two different results:&amp;nbsp;Results for Serious Smoker Population (&amp;gt;35%) and&amp;nbsp;Results for Moderate Smoker Population (&amp;lt;=35%), by adding "Status" variable saying "Serious" for &amp;gt;35% and "Moderate" for &amp;lt;=35%.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know I don't need to use macro, but I'd like to approach more complicated dataset soon by knowing how to use macro with if then statement. Thanks!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Jun 2017 01:58:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-macro-if-then-else/m-p/368993#M88018</guid>
      <dc:creator>cwpark</dc:creator>
      <dc:date>2017-06-21T01:58:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to use macro %if %then; %else;?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-macro-if-then-else/m-p/368998#M88021</link>
      <description>&lt;P&gt;I agree with the importance of learning how to write macros, but I'm not sure how a macro could help you here. Here are two non-macro approaches:&lt;/P&gt;
&lt;PRE&gt;data smoker;
input PctSmokers Income $ Age $; 
datalines; 
45 1 1
35 2 2
14 5 3
27 1 1
20 2 2
;

data want;
  set smoker;
  length Status $8;
  if PctSmokers&amp;gt;35 then Status="Serious";
  else if 0&amp;lt;=PctSmokers&amp;lt;=35 then Status="Moderate";
run;

proc format;
  value status
  low-35='Moderate'
  36-High='Serious'
  ;
run;

proc print data=smoker;
  format PctSmokers status.;
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Jun 2017 02:43:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-macro-if-then-else/m-p/368998#M88021</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-06-21T02:43:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to use macro %if %then; %else;?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-macro-if-then-else/m-p/369201#M88112</link>
      <description>&lt;P&gt;Thank you very much!&amp;nbsp;&lt;img id="smileyvery-happy" class="emoticon emoticon-smileyvery-happy" src="https://communities.sas.com/i/smilies/16x16_smiley-very-happy.png" alt="Smiley Very Happy" title="Smiley Very Happy" /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Jun 2017 15:50:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-macro-if-then-else/m-p/369201#M88112</guid>
      <dc:creator>cwpark</dc:creator>
      <dc:date>2017-06-21T15:50:05Z</dc:date>
    </item>
  </channel>
</rss>

