<?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: local macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/local-macro/m-p/586869#M167534</link>
    <description>&lt;P&gt;Thanks for your response.&amp;nbsp;&amp;nbsp;Yes, all the variables involved, i.e. flag_ref1 - flag_ref3, ref1 - ref3 are data set variables.&amp;nbsp; However, in my actual code there are close to 50 variables that follow this same pattern.&amp;nbsp;To avoid all of that additional coding,&amp;nbsp;I thought a macro would be better than an array.&amp;nbsp; However, maybe there are unintended issues with using the macro?&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 06 Sep 2019 20:24:59 GMT</pubDate>
    <dc:creator>sophia_SAS</dc:creator>
    <dc:date>2019-09-06T20:24:59Z</dc:date>
    <item>
      <title>local macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/local-macro/m-p/586461#M167415</link>
      <description>&lt;DIV&gt;&lt;FONT&gt;Hi SAS users!&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT&gt;I have 3 flags:&amp;nbsp;&lt;FONT&gt;flag_REF1, flag_REF2, flag_REF3 and where each flag is noted (=1), then I want to void &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT&gt;&lt;FONT&gt;that corresponding REF value. &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT&gt;&lt;FONT&gt;So in short I'm trying to produce the following steps but in a local macro:&lt;/FONT&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT&gt;&lt;FONT&gt;1. flag_REF1=1 then&amp;nbsp;REF1=.;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT&gt;&lt;FONT&gt;2. flag_REF2=1 then REF2=.;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT&gt;&lt;FONT&gt;3. flag_REF3=1 then REF3=.;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT&gt;&lt;FONT&gt;However, it's not working. Any thoughts on where I'm going wrong? &lt;/FONT&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT&gt;data want;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT&gt;set have;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT&gt;&lt;BR /&gt;options mprint;&lt;BR /&gt;%macro loop;&lt;BR /&gt;&amp;nbsp;%local i;&lt;BR /&gt;&amp;nbsp; %do i=1 %to 3;&lt;BR /&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT&gt;%if flag_REF&amp;amp;i=1 %then %do; REF&amp;amp;i=.; %end;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;%end;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT&gt;%mend loop;&lt;BR /&gt;%loop;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT&gt;Thanks!&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT&gt;run;&lt;BR /&gt;&lt;/FONT&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 05 Sep 2019 16:33:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/local-macro/m-p/586461#M167415</guid>
      <dc:creator>sophia_SAS</dc:creator>
      <dc:date>2019-09-05T16:33:09Z</dc:date>
    </item>
    <item>
      <title>Re: local macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/local-macro/m-p/586463#M167416</link>
      <description>&lt;P&gt;Are flag_ref1 flag_ref2 flag_ref3 data set variables or macro variables? Are ref1 ref2 and ref3 data set variables or macro variables?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Where are their values set?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If they are data set variables, please look at the data set HAVE with your own eyes to see if they have the values you expect them to have. If they are macro variables, please use the %PUT command to look at the values contained by these macro variables; do they have the values that you expect them to have?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Don't use the phrase "it's not working". We can't ever help you with such limited information. Explain what is not working and how you know that. Please show us the SAS log, first add OPTIONS MPRINT; to the first line of your code and then run it again, and provide us the log by clicking on the {i} icon and paste the log as text into the window that appears.&amp;nbsp;&lt;STRONG&gt;Do not skip this step.&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Sep 2019 16:40:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/local-macro/m-p/586463#M167416</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-09-05T16:40:33Z</dc:date>
    </item>
    <item>
      <title>Re: local macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/local-macro/m-p/586465#M167417</link>
      <description>&lt;P&gt;Are you trying to change the values of variables in a data set? Or the values of macro variables?&lt;/P&gt;</description>
      <pubDate>Thu, 05 Sep 2019 16:38:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/local-macro/m-p/586465#M167417</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-09-05T16:38:55Z</dc:date>
    </item>
    <item>
      <title>Re: local macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/local-macro/m-p/586466#M167418</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/9463"&gt;@sophia_SAS&lt;/a&gt;&amp;nbsp; You should ideally avoid macros and use arrays instead. However, if you really want to use macros your logic should be&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro loop;
 %local i;
  %do i=1 %to 3;
 
  if flag_REF&amp;amp;i=1 then REF&amp;amp;i=.;
 
 %end;
%mend loop;
%loop&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 05 Sep 2019 16:41:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/local-macro/m-p/586466#M167418</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-09-05T16:41:40Z</dc:date>
    </item>
    <item>
      <title>Re: local macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/local-macro/m-p/586469#M167419</link>
      <description>&lt;P&gt;Make sure the macro is generating the SAS code you want to run.&lt;/P&gt;
&lt;P&gt;To make your program easier to understand define the macro BEFORE starting the data step where you are going to CALL the macro.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro loop;
%local i;
%do i=1 %to 3;
if flag_REF&amp;amp;i=1 then REF&amp;amp;i=.;
%end;
%mend loop;

options mprint;
data want;
  set have;
 %loop;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 05 Sep 2019 16:42:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/local-macro/m-p/586469#M167419</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-09-05T16:42:41Z</dc:date>
    </item>
    <item>
      <title>Re: local macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/local-macro/m-p/586471#M167420</link>
      <description>Why would you want to introduce macro quoting by using the %STR() macro function?&lt;BR /&gt;</description>
      <pubDate>Thu, 05 Sep 2019 16:44:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/local-macro/m-p/586471#M167420</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-09-05T16:44:35Z</dc:date>
    </item>
    <item>
      <title>Re: local macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/local-macro/m-p/586473#M167421</link>
      <description>&lt;P&gt;Sir sorry,I edited coz i wanted to see the generated statements in the log &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro loop;
 %local i;
  %do i=1 %to 3;
 
%put %str( if flag_REF&amp;amp;i=1 then REF&amp;amp;i=.;); 
 
 %end;
%mend loop;
%loop&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; if flag_REF1=1 then REF1=.;
 if flag_REF2=1 then REF2=.;
 if flag_REF3=1 then REF3=.;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I generally do that to see what's happening, but you caught me too fast before I could edit like a cop:)&lt;/P&gt;</description>
      <pubDate>Thu, 05 Sep 2019 16:46:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/local-macro/m-p/586473#M167421</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-09-05T16:46:46Z</dc:date>
    </item>
    <item>
      <title>Re: local macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/local-macro/m-p/586488#M167424</link>
      <description>&lt;P&gt;If the variables involved are all data set variables then no need for macros. That is the sort thing array processing is designed for.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want;
   set have;
   array frf flag_ref1 - flag_ref3;
   array  rf ref1 - ref3;
   do i=1 to dim(frf);
      if frf[i]=1 then call missing(rf[i]);
   end;
   drop i;
run;&lt;/PRE&gt;
&lt;P&gt;The code savings would be more obvious if there were 50 of each variable though.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Sep 2019 17:16:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/local-macro/m-p/586488#M167424</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-09-05T17:16:12Z</dc:date>
    </item>
    <item>
      <title>Re: local macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/local-macro/m-p/586869#M167534</link>
      <description>&lt;P&gt;Thanks for your response.&amp;nbsp;&amp;nbsp;Yes, all the variables involved, i.e. flag_ref1 - flag_ref3, ref1 - ref3 are data set variables.&amp;nbsp; However, in my actual code there are close to 50 variables that follow this same pattern.&amp;nbsp;To avoid all of that additional coding,&amp;nbsp;I thought a macro would be better than an array.&amp;nbsp; However, maybe there are unintended issues with using the macro?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Sep 2019 20:24:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/local-macro/m-p/586869#M167534</guid>
      <dc:creator>sophia_SAS</dc:creator>
      <dc:date>2019-09-06T20:24:59Z</dc:date>
    </item>
    <item>
      <title>Re: local macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/local-macro/m-p/586871#M167536</link>
      <description>&lt;P&gt;Thanks for your solution. I really like the suggestion to define the macro before the data step. This is something I don't regularly do, but will now!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Sep 2019 20:27:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/local-macro/m-p/586871#M167536</guid>
      <dc:creator>sophia_SAS</dc:creator>
      <dc:date>2019-09-06T20:27:26Z</dc:date>
    </item>
    <item>
      <title>Re: local macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/local-macro/m-p/586873#M167537</link>
      <description>&lt;P&gt;Hi Novinosrin,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your solution! This was what I was looking for. To get to your point about using an array vs a macro. My actual code contains around 50 variables that follow this same pattern. To avoid all of that additional coding,&amp;nbsp;I thought a macro would be better than an array.&amp;nbsp; But maybe not?&amp;nbsp; Why do you suggest I avoid a macro for this example?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again!&lt;/P&gt;</description>
      <pubDate>Fri, 06 Sep 2019 20:29:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/local-macro/m-p/586873#M167537</guid>
      <dc:creator>sophia_SAS</dc:creator>
      <dc:date>2019-09-06T20:29:54Z</dc:date>
    </item>
  </channel>
</rss>

