<?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: Code is not working as intended in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Code-is-not-working-as-intended/m-p/886333#M350245</link>
    <description>&lt;P&gt;If you want to use macro variable abc outside of macro, you need to make it a global macro variable:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let x= 2020Q1;
%let y= 0;

%macro xyz();
%global abc;
%if &amp;amp;y =0 %then 
%let abc = %sysfunc(intnx(qtr, %sysfunc(inputn(&amp;amp;x, yyq6.)),0,b),yyq6.);
%mend;

%xyz;
%put &amp;amp;=abc;

ABC=2020Q1&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And you may want to know&amp;nbsp;&lt;A href="https://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a002047080.htm" target="_self"&gt;Scopes of Macro Variables&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 26 Jul 2023 02:22:38 GMT</pubDate>
    <dc:creator>whymath</dc:creator>
    <dc:date>2023-07-26T02:22:38Z</dc:date>
    <item>
      <title>Code is not working as intended</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Code-is-not-working-as-intended/m-p/886329#M350242</link>
      <description>&lt;P&gt;%let x= 2020Q1;&lt;/P&gt;&lt;P&gt;%let y= 0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro xyz();&lt;/P&gt;&lt;P&gt;%if &amp;amp;y =0 %then&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let abc = %sysfunc(intnx(qtr, %sysfunc(inputn(&amp;amp;x, yyq6.)),0,b),yyq6.);&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;%xyz;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;when I execute the above code, the macro abc is not resolved. Can anyone please help?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks in advance.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jul 2023 01:53:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Code-is-not-working-as-intended/m-p/886329#M350242</guid>
      <dc:creator>atinytale</dc:creator>
      <dc:date>2023-07-26T01:53:53Z</dc:date>
    </item>
    <item>
      <title>Re: Code is not working as intended</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Code-is-not-working-as-intended/m-p/886333#M350245</link>
      <description>&lt;P&gt;If you want to use macro variable abc outside of macro, you need to make it a global macro variable:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let x= 2020Q1;
%let y= 0;

%macro xyz();
%global abc;
%if &amp;amp;y =0 %then 
%let abc = %sysfunc(intnx(qtr, %sysfunc(inputn(&amp;amp;x, yyq6.)),0,b),yyq6.);
%mend;

%xyz;
%put &amp;amp;=abc;

ABC=2020Q1&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And you may want to know&amp;nbsp;&lt;A href="https://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a002047080.htm" target="_self"&gt;Scopes of Macro Variables&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jul 2023 02:22:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Code-is-not-working-as-intended/m-p/886333#M350245</guid>
      <dc:creator>whymath</dc:creator>
      <dc:date>2023-07-26T02:22:38Z</dc:date>
    </item>
  </channel>
</rss>

