<?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: I cannot figure out this code is not working in proper way... please help in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/I-cannot-figure-out-this-code-is-not-working-in-proper-way/m-p/329955#M73903</link>
    <description>&lt;P&gt;When &amp;amp;RE is A, this line gets generated:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if A = "A" then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That comparison is never true, so the ELSE condition always kicks in.&lt;/P&gt;</description>
    <pubDate>Sat, 04 Feb 2017 14:24:08 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2017-02-04T14:24:08Z</dc:date>
    <item>
      <title>I cannot figure out this code is not working in proper way... please help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-cannot-figure-out-this-code-is-not-working-in-proper-way/m-p/329953#M73902</link>
      <description>&lt;P&gt;Does anyone please give advice to me how come the result is not&amp;nbsp;A?&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;Here the sample code below:&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%global result;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%macro addd(re);&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;data _null_;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; if &amp;amp;re = "A" then do;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;call symputx('result','A');&lt;BR /&gt;&amp;nbsp; &amp;nbsp; end;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; else do;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; call symputx('result','B');&lt;BR /&gt;&amp;nbsp; &amp;nbsp; end;&lt;BR /&gt;&amp;nbsp; run;&lt;BR /&gt;%mend;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data readds;&lt;BR /&gt;&amp;nbsp; input posit $;&lt;BR /&gt;datalines;&lt;BR /&gt;&amp;nbsp;A&lt;BR /&gt;&amp;nbsp;;&lt;BR /&gt;&amp;nbsp;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;set readds;&lt;BR /&gt;&amp;nbsp; rc = dosubl('%addd('||posit||');');&lt;BR /&gt;&amp;nbsp; collectresult=symget('result');&lt;BR /&gt;&amp;nbsp; put collectresult=;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;RESULT:&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;collectresult=B&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 04 Feb 2017 13:27:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-cannot-figure-out-this-code-is-not-working-in-proper-way/m-p/329953#M73902</guid>
      <dc:creator>Olime</dc:creator>
      <dc:date>2017-02-04T13:27:12Z</dc:date>
    </item>
    <item>
      <title>Re: I cannot figure out this code is not working in proper way... please help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-cannot-figure-out-this-code-is-not-working-in-proper-way/m-p/329955#M73903</link>
      <description>&lt;P&gt;When &amp;amp;RE is A, this line gets generated:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if A = "A" then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That comparison is never true, so the ELSE condition always kicks in.&lt;/P&gt;</description>
      <pubDate>Sat, 04 Feb 2017 14:24:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-cannot-figure-out-this-code-is-not-working-in-proper-way/m-p/329955#M73903</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-02-04T14:24:08Z</dc:date>
    </item>
    <item>
      <title>Re: I cannot figure out this code is not working in proper way... please help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-cannot-figure-out-this-code-is-not-working-in-proper-way/m-p/329956#M73904</link>
      <description>Hi:&lt;BR /&gt;  I'm not sure what you are trying to do, but I am fairly sure that this is wrong:&lt;BR /&gt;      if &amp;amp;re = "A" then do;&lt;BR /&gt;&lt;BR /&gt;  What notes do you see in the log? I would expect you to see:&lt;BR /&gt;NOTE: Variable A is uninitialized.&lt;BR /&gt;&lt;BR /&gt;Because your data step IF statement is asking whether the macro variable value &amp;amp;re is equal to the quoted string "A". As far as I can tell, you do NOT have a data step variable called A -- you have a macro variable whose value is A and so this statement: &lt;BR /&gt;    if &amp;amp;re = "A" then do;&lt;BR /&gt;resolves to&lt;BR /&gt;   if A = "A" then do;&lt;BR /&gt;&lt;BR /&gt;which has to be false, since variable A does not exist.&lt;BR /&gt;&lt;BR /&gt;  If you are trying to test the value of a macro variable, then you should use a %IF.&lt;BR /&gt;&lt;BR /&gt;  However, since it's still not clear to me what you want to do, I don't have any other suggestions except that you rethink your logic and investigate the correct way to refer to macro variables and the difference between DATA step IF and Macro %IF.&lt;BR /&gt; &lt;BR /&gt;cynthia&lt;BR /&gt;</description>
      <pubDate>Sat, 04 Feb 2017 14:28:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-cannot-figure-out-this-code-is-not-working-in-proper-way/m-p/329956#M73904</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2017-02-04T14:28:12Z</dc:date>
    </item>
    <item>
      <title>Re: I cannot figure out this code is not working in proper way... please help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-cannot-figure-out-this-code-is-not-working-in-proper-way/m-p/329962#M73907</link>
      <description>&lt;P&gt;The problem is with your macro. So let's ignore the complications of the extra data step and DOSUBL call and just call the macro directly to see what is happening. Since your macro is just generating SAS code we an turn on the MPRINT option and see what it does. &amp;nbsp;So here is program that can test that (I simplified the macro so that is not so many lines of code).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%global result;
%macro addd(re);
data _null_;
  if &amp;amp;re = "A" then call symputx('result','A');
  else call symputx('result','B');
run;
%mend addd;

options mprint;
%addd(A)
%put &amp;amp;=result;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And here is the results from the LOG.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;53   %addd(A)
MPRINT(ADDD):   data _null_;
MPRINT(ADDD):   if A = "A" then call symputx('result','A');
MPRINT(ADDD):   else call symputx('result','B');
MPRINT(ADDD):   run;

NOTE: Variable A is uninitialized.
NOTE: DATA statement used (Total process time):
      real time           0.08 seconds
      cpu time            0.00 seconds


54   %put &amp;amp;=result;
RESULT=B&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;As you can see SAS could not find a variable named A to compare to the string literal 'A' so the comparison was false. It will be false unless you call it with a string literal as the value of the parameter : &amp;nbsp;%ADDD(re='A') or %ADDD(re="A");&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you really wanted a line of data step code that would compare the value of the macro variable RE to the character A then you would want something like this.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  if "&amp;amp;re" = "A" then call symputx('result','A');&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 04 Feb 2017 15:35:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-cannot-figure-out-this-code-is-not-working-in-proper-way/m-p/329962#M73907</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-02-04T15:35:06Z</dc:date>
    </item>
  </channel>
</rss>

