<?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: creating new variable with macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/creating-new-variable-with-macro/m-p/74161#M15997</link>
    <description>Lisam,&lt;BR /&gt;
&lt;BR /&gt;
You seem to have missed the %LET from your macro assignments.&lt;BR /&gt;
&lt;BR /&gt;
Try:&lt;BR /&gt;
&lt;BR /&gt;
%macro test(var);&lt;BR /&gt;
 %if &amp;amp;var=1 %then %LET d1_&amp;amp;var=1;&lt;BR /&gt;
 %else %LET d1_&amp;amp;var=0;&lt;BR /&gt;
 %if &amp;amp;var=2 %then %LET d2_&amp;amp;var=1;&lt;BR /&gt;
 %else  %LET d2_&amp;amp;var=0;&lt;BR /&gt;
%mend test;&lt;BR /&gt;
&lt;BR /&gt;
You don't need the run statement since it is part of the data step and you're code is purely Macro language.&lt;BR /&gt;
&lt;BR /&gt;
Hope this is enough for you.&lt;BR /&gt;
&lt;BR /&gt;
Regards,&lt;BR /&gt;
&lt;BR /&gt;
BPD</description>
    <pubDate>Mon, 16 Feb 2009 08:28:22 GMT</pubDate>
    <dc:creator>BPD</dc:creator>
    <dc:date>2009-02-16T08:28:22Z</dc:date>
    <item>
      <title>creating new variable with macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-new-variable-with-macro/m-p/74160#M15996</link>
      <description>I am trying to create dummy variables using if then statements in a simple macro (I would like them to be called d1_var and d2_var or some prefix or suffix tied to the variable name). For some reason, the new variables are not being created and I think there must be a simple explaination. Any ideas?&lt;BR /&gt;
&lt;BR /&gt;
%macro test(var);&lt;BR /&gt;
%if &amp;amp;var=1 %then d1_&amp;amp;var=1;&lt;BR /&gt;
%else d1_&amp;amp;var=0;&lt;BR /&gt;
%if &amp;amp;var=2 %then d2_&amp;amp;var=1;&lt;BR /&gt;
%else d2_&amp;amp;var=0;&lt;BR /&gt;
run;&lt;BR /&gt;
%mend test;&lt;BR /&gt;
&lt;BR /&gt;
%test(var1);&lt;BR /&gt;
%test(var2);&lt;BR /&gt;
etc.</description>
      <pubDate>Mon, 16 Feb 2009 04:18:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-new-variable-with-macro/m-p/74160#M15996</guid>
      <dc:creator>lisam</dc:creator>
      <dc:date>2009-02-16T04:18:56Z</dc:date>
    </item>
    <item>
      <title>Re: creating new variable with macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-new-variable-with-macro/m-p/74161#M15997</link>
      <description>Lisam,&lt;BR /&gt;
&lt;BR /&gt;
You seem to have missed the %LET from your macro assignments.&lt;BR /&gt;
&lt;BR /&gt;
Try:&lt;BR /&gt;
&lt;BR /&gt;
%macro test(var);&lt;BR /&gt;
 %if &amp;amp;var=1 %then %LET d1_&amp;amp;var=1;&lt;BR /&gt;
 %else %LET d1_&amp;amp;var=0;&lt;BR /&gt;
 %if &amp;amp;var=2 %then %LET d2_&amp;amp;var=1;&lt;BR /&gt;
 %else  %LET d2_&amp;amp;var=0;&lt;BR /&gt;
%mend test;&lt;BR /&gt;
&lt;BR /&gt;
You don't need the run statement since it is part of the data step and you're code is purely Macro language.&lt;BR /&gt;
&lt;BR /&gt;
Hope this is enough for you.&lt;BR /&gt;
&lt;BR /&gt;
Regards,&lt;BR /&gt;
&lt;BR /&gt;
BPD</description>
      <pubDate>Mon, 16 Feb 2009 08:28:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-new-variable-with-macro/m-p/74161#M15997</guid>
      <dc:creator>BPD</dc:creator>
      <dc:date>2009-02-16T08:28:22Z</dc:date>
    </item>
  </channel>
</rss>

