<?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: Macro variable delete contents in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-delete-contents/m-p/835421#M330291</link>
    <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;My question is, if it is possible to delete the contents/value of the macro variable quantile within the macro test&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Place this where it belongs&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let quantile=;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I suggest a re-write of the logic and sequencing of your macros. Nested macro&amp;nbsp;&lt;EM&gt;definitions&lt;/EM&gt; is not a good idea. With your nested macro definitions, you have an %end; in the wrong place. It's also not clear to me why you need the %global statement, but it doesn't hurt anything here.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%global year quantile;

%macro choose;
    %do qual=1 %to 3;
        %let quantile=%scan(&amp;amp;Matchquality.,&amp;amp;qual.);
              /* some further steps in this loop */
    %end;
%mend choose;

%macro test;
    %do year=2017 %to 2019;
        %choose
    %end;
%mend test;

%test&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 27 Sep 2022 13:54:23 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2022-09-27T13:54:23Z</dc:date>
    <item>
      <title>Macro variable delete contents</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-delete-contents/m-p/835420#M330290</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I have defined a global macro variable quantile and want to use it in a sas macro within a double loop. The macro and loops look like this:&lt;/P&gt;&lt;P&gt;%global year quantile;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro test;&lt;/P&gt;&lt;P&gt;%do year=2017 %to 2019;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %macro choose;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; %do qual=1 %to 3;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; %let quantile=%scan(&amp;amp;Matchquality.,&amp;amp;qual.);&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;/* some further steps in this loop */&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %mend choose;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; /* invocation of other macros which are using the macro variable quantile */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* Before doing the loop for new year, I would like to delete the value of quantile without loosing its status 'global' */&lt;/P&gt;&lt;P&gt;%mend test;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My question is, if it is possible to delete the contents/value of the macro variable quantile within the macro test without deleting the whole macro variable?&lt;/P&gt;&lt;P&gt;My problem is that the macro variable quantile has to be global. By deleting it, it loses the status global because it is defined in the sas macro choose.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your answer&lt;/P&gt;&lt;P&gt;sasstats&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;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Sep 2022 12:57:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-delete-contents/m-p/835420#M330290</guid>
      <dc:creator>sasstats</dc:creator>
      <dc:date>2022-09-27T12:57:04Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable delete contents</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-delete-contents/m-p/835421#M330291</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;My question is, if it is possible to delete the contents/value of the macro variable quantile within the macro test&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Place this where it belongs&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let quantile=;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I suggest a re-write of the logic and sequencing of your macros. Nested macro&amp;nbsp;&lt;EM&gt;definitions&lt;/EM&gt; is not a good idea. With your nested macro definitions, you have an %end; in the wrong place. It's also not clear to me why you need the %global statement, but it doesn't hurt anything here.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%global year quantile;

%macro choose;
    %do qual=1 %to 3;
        %let quantile=%scan(&amp;amp;Matchquality.,&amp;amp;qual.);
              /* some further steps in this loop */
    %end;
%mend choose;

%macro test;
    %do year=2017 %to 2019;
        %choose
    %end;
%mend test;

%test&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Sep 2022 13:54:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-delete-contents/m-p/835421#M330291</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-09-27T13:54:23Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable delete contents</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-delete-contents/m-p/835430#M330292</link>
      <description>&lt;P&gt;If you want to change the value of a macro variable just use a %LET statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let quantile=;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What are you actually trying to do?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First thing is do NOT define macros inside of each other.&amp;nbsp; That will just confuse you.&amp;nbsp; Unlike macro variables there is no "scope" for a macro definition. All of the macros are defined in the same name space.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro choose;
%do qual=1 %to 3;
    %let quantile=%scan(&amp;amp;Matchquality.,&amp;amp;qual.);
       /* some further steps in this loop */
%end;
%mend choose;

%macro test;
%do year=2017 %to 2019;
  /* invocation of other macros which are using the macro variable quantile */
  /* Before doing the loop for new year, 
     I would like to delete the value of quantile without loosing its status 'global' 
  */
  %let quantile=;
%end ;
%mend test;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Other comments.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use LOCAL macro variables.&amp;nbsp; For example QUAL looks like a local macro variable for the %CHOOSE() macro and YEAR looks like a local macro variable for the %TEST() macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use parameters to pass values into the macros.&amp;nbsp; Do not just reference "magic" macro variables in the middle of a macro definition.&amp;nbsp; Like the way that the %CHOOSE() macro is just assuming that the macro variable Matchquality will have magically been defined with a value before the macro started running.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Sep 2022 15:57:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-delete-contents/m-p/835430#M330292</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-09-27T15:57:39Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable delete contents</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-delete-contents/m-p/835446#M330294</link>
      <description>&lt;P&gt;While the replies you have seen so far are both correct, I'm going to take a different path.&amp;nbsp; After all, the code you have posted would have no need to remove the macro variable &amp;amp;quantile, since it would just get replaced whenever %choose executes.&amp;nbsp; However ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code you have posted doesn't actually assign a value to &amp;amp;quantile.&amp;nbsp; It never actually runs %choose.&amp;nbsp; Perhaps that is the reason you have having some difficulty here.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps&amp;nbsp; you like the structure to your program and don't want to follow the suggestions about not defining a macro within another macro.&amp;nbsp; That is still very possible here.&amp;nbsp; There is no need to define %choose.&amp;nbsp; You could just remove the %macro choose and %mend choose statements, and let the logic execute without defining a macro for it.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Sep 2022 14:48:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-delete-contents/m-p/835446#M330294</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2022-09-27T14:48:18Z</dc:date>
    </item>
  </channel>
</rss>

