<?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 Changing variable values using macros in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Changing-variable-values-using-macros/m-p/431879#M281741</link>
    <description>&lt;P&gt;I am trying to dichotomise a few variables using a 0.5 threshold.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%MACRO dichot(dichVar=);&lt;/P&gt;&lt;P&gt;data quasi.MVNdi;&lt;BR /&gt;set quasi.MVN;&lt;BR /&gt;%if &amp;amp;dichVar &amp;lt; 0.5 %then &amp;amp;dichVar = 0;&lt;BR /&gt;%else &amp;amp;dichVar = 1;; /*WHY THERE HAS TO BE 2 SEMICOLONS*/&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;proc print data=quasi.mdi;&lt;BR /&gt;var &amp;amp;dichVar;&lt;BR /&gt;run;;&lt;/P&gt;&lt;P&gt;%MEND dichot;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%dichot(dichvar=Latest_lipid_drug);&lt;BR /&gt;%dichot(dichvar=Latest_diabetes);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;somehow the results that came out were all 1 (for both variables, original values are normally distributed between -1 to 1).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anywhere wrong with the code? Thanks.&lt;/P&gt;</description>
    <pubDate>Mon, 29 Jan 2018 17:31:59 GMT</pubDate>
    <dc:creator>lyfaqu</dc:creator>
    <dc:date>2018-01-29T17:31:59Z</dc:date>
    <item>
      <title>Changing variable values using macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-variable-values-using-macros/m-p/431879#M281741</link>
      <description>&lt;P&gt;I am trying to dichotomise a few variables using a 0.5 threshold.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%MACRO dichot(dichVar=);&lt;/P&gt;&lt;P&gt;data quasi.MVNdi;&lt;BR /&gt;set quasi.MVN;&lt;BR /&gt;%if &amp;amp;dichVar &amp;lt; 0.5 %then &amp;amp;dichVar = 0;&lt;BR /&gt;%else &amp;amp;dichVar = 1;; /*WHY THERE HAS TO BE 2 SEMICOLONS*/&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;proc print data=quasi.mdi;&lt;BR /&gt;var &amp;amp;dichVar;&lt;BR /&gt;run;;&lt;/P&gt;&lt;P&gt;%MEND dichot;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%dichot(dichvar=Latest_lipid_drug);&lt;BR /&gt;%dichot(dichvar=Latest_diabetes);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;somehow the results that came out were all 1 (for both variables, original values are normally distributed between -1 to 1).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anywhere wrong with the code? Thanks.&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jan 2018 17:31:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-variable-values-using-macros/m-p/431879#M281741</guid>
      <dc:creator>lyfaqu</dc:creator>
      <dc:date>2018-01-29T17:31:59Z</dc:date>
    </item>
    <item>
      <title>Re: Changing variable values using macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-variable-values-using-macros/m-p/431880#M281742</link>
      <description>&lt;P&gt;one is for the macro processor and the other is for compiler. It's all about timing just like in life &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;RTM- macro tokenisation process&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jan 2018 17:35:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-variable-values-using-macros/m-p/431880#M281742</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-01-29T17:35:04Z</dc:date>
    </item>
    <item>
      <title>Re: Changing variable values using macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-variable-values-using-macros/m-p/431884#M281743</link>
      <description>&lt;P&gt;In other words ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;macro language does not read the contents of a DATA set (in nearly all cases).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use DATA step statements:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;IF instead of %IF&lt;/P&gt;
&lt;P&gt;THEN instead of %THEN&lt;/P&gt;
&lt;P&gt;ELSE instead of %ELSE&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You won't need two semicolons any longer, and best of all, you will get an accurate result.&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jan 2018 17:39:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-variable-values-using-macros/m-p/431884#M281743</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-01-29T17:39:53Z</dc:date>
    </item>
    <item>
      <title>Re: Changing variable values using macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-variable-values-using-macros/m-p/431886#M281744</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/157206"&gt;@lyfaqu&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;I am trying to dichotomise a few variables using a 0.5 threshold.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%MACRO dichot(dichVar=);&lt;/P&gt;
&lt;P&gt;data quasi.MVNdi;&lt;BR /&gt;set quasi.MVN;&lt;BR /&gt;%if &amp;amp;dichVar &amp;lt; 0.5 %then &amp;amp;dichVar = 0;&lt;BR /&gt;%else &amp;amp;dichVar = 1;; /*WHY THERE HAS TO BE 2 SEMICOLONS*/&lt;BR /&gt;RUN;&lt;/P&gt;
&lt;P&gt;proc print data=quasi.mdi;&lt;BR /&gt;var &amp;amp;dichVar;&lt;BR /&gt;run;;&lt;/P&gt;
&lt;P&gt;%MEND dichot;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%dichot(dichvar=Latest_lipid_drug);&lt;BR /&gt;%dichot(dichvar=Latest_diabetes);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;somehow the results that came out were all 1 (for both variables, original values are normally distributed between -1 to 1).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anywhere wrong with the code? Thanks.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Basically I do not see any need for a macro anywhere.&lt;/P&gt;
&lt;P&gt;Any time you see a requirement to do the exact same thing to multiple variables think ARRAY instead and process all of them at once&lt;/P&gt;
&lt;P&gt;Some thing like:&lt;/P&gt;
&lt;PRE&gt;data quasi.MVNdi;
   set quasi.MVN;
   array di Latest_lipid_drug Latest_diabetes ;
   do i = 1 to dim(di);
      if not missing di[i] then di[i]= di[i] ge 0.5;
   end;
   drop i;
RUN;&lt;/PRE&gt;
&lt;P&gt;Likely Problems: 1) You overwrite the output data set with each call for a single variable 2) total execution time increases with more variables. 3) You need to be careful with &amp;lt;&amp;nbsp; or &amp;lt;= comparisons about whether you want missing values included or not. Missing is &amp;lt; any explicit value 4) Since macro variables are compared at the compilation phase you aren't generating the code you think you are.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%if DOES NOT evaluate data step values but macro variable values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As for why the two semicolons: run your code like this:&lt;/P&gt;
&lt;P&gt;options mprint symbolgen;&lt;/P&gt;
&lt;P&gt;%dichot(dichvar=Latest_lipid_drug);&lt;/P&gt;
&lt;P&gt;to see what the macro is generating.&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;the t&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jan 2018 17:45:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-variable-values-using-macros/m-p/431886#M281744</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-01-29T17:45:27Z</dc:date>
    </item>
  </channel>
</rss>

