<?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: Resolving Macro in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Resolving-Macro-Variable/m-p/584025#M14081</link>
    <description>Wow. It is a detailed solution. Understood where I went wrong. Thank you. Another question, if I need a result: &amp;amp;ABC. ,after resolving a macro variable print(n=ABC). How will write in program?</description>
    <pubDate>Mon, 26 Aug 2019 18:54:00 GMT</pubDate>
    <dc:creator>Ramya2</dc:creator>
    <dc:date>2019-08-26T18:54:00Z</dc:date>
    <item>
      <title>Resolving Macro Variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Resolving-Macro-Variable/m-p/584013#M14072</link>
      <description>&lt;P&gt;Hi Team,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a scenario like, After resolving a macro I need the result as &amp;amp;n. How do I get this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro print(into=);&lt;/P&gt;
&lt;P&gt;proc sql;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;select strip(put(count(distinct USUBJID), 8.)) into: &amp;amp;into0. separated by ' '&lt;BR /&gt;from XYZ.;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Quit;&lt;/P&gt;
&lt;P&gt;%mend;&lt;/P&gt;
&lt;P&gt;%print(into=ABC);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%put &amp;amp;ABC.;&amp;nbsp; ---&amp;gt; this step is not giving me any result. I can keep this inside a macro, But when I have more than one macro calls then this will not work. Kindly anyone please help.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Aug 2019 18:59:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Resolving-Macro-Variable/m-p/584013#M14072</guid>
      <dc:creator>Ramya2</dc:creator>
      <dc:date>2019-08-26T18:59:00Z</dc:date>
    </item>
    <item>
      <title>Re: Resolving Macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Resolving-Macro-Variable/m-p/584014#M14073</link>
      <description>&lt;P&gt;Macro variable scope, the macro variable exists within the macro but does not exist outside. If you want to access it outside the macro, create it as a global macro variable. &lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%global &amp;amp;into;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;Adding that into your macro should solve your issues. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That 0 may cause issues though, not sure if that's intentional or not.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;select strip(put(count(distinct USUBJID), 8.)) into: &lt;FONT size="5" color="#FF0000"&gt;&lt;STRONG&gt;&amp;amp;into0.&lt;/STRONG&gt; &lt;/FONT&gt;separated by ' '
from XYZ.;&lt;/PRE&gt;
&lt;P&gt;That would create a macro variable called ABC0, not ABC.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/254855"&gt;@Ramya2&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi Team,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a scenario like, After resolving a macro I need the result as &amp;amp;n. How do I get this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro print(into=);&lt;/P&gt;
&lt;P&gt;proc sql;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;select strip(put(count(distinct USUBJID), 8.)) into: &amp;amp;into0. separated by ' '&lt;BR /&gt;from XYZ.;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Quit;&lt;/P&gt;
&lt;P&gt;%mend;&lt;/P&gt;
&lt;P&gt;%print(into=ABC);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%put &amp;amp;ABC.;&amp;nbsp; ---&amp;gt; this step is not giving me any result. I can keep this inside a macro, But when I have more than one macro calls then this will not work. Kindly anyone please help.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Aug 2019 18:23:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Resolving-Macro-Variable/m-p/584014#M14073</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-08-26T18:23:08Z</dc:date>
    </item>
    <item>
      <title>Re: Resolving Macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Resolving-Macro-Variable/m-p/584017#M14075</link>
      <description>Hi Reeza, Thank you for the solution. Yeah that Zero was not intentional. I have another quick question. if I want result as &amp;amp;n. and n is macro parameter n=ABC. How do I write it. I tried &amp;amp;&amp;amp;n.. , thinking &amp;amp;n. will resolve macro and remaining &amp;amp;n. will give me a result. But this is quiet Rubbish. Please help me.</description>
      <pubDate>Mon, 26 Aug 2019 18:33:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Resolving-Macro-Variable/m-p/584017#M14075</guid>
      <dc:creator>Ramya2</dc:creator>
      <dc:date>2019-08-26T18:33:28Z</dc:date>
    </item>
    <item>
      <title>Re: Resolving Macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Resolving-Macro-Variable/m-p/584019#M14076</link>
      <description>Sorry, Correcting above requirement, need result as &amp;amp;ABC.</description>
      <pubDate>Mon, 26 Aug 2019 18:35:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Resolving-Macro-Variable/m-p/584019#M14076</guid>
      <dc:creator>Ramya2</dc:creator>
      <dc:date>2019-08-26T18:35:03Z</dc:date>
    </item>
    <item>
      <title>Re: Resolving Macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Resolving-Macro-Variable/m-p/584022#M14079</link>
      <description>&lt;P&gt;Assuming the extra 0 is just a type there are two issues here.&lt;/P&gt;
&lt;P&gt;First a scoping issue.&amp;nbsp; You are calling a macro and asking it to create a macro variable named ABC. If no sure macro variable exists when the macro runs then it will be created in the macro's scope. Which means it will then disappear after the macro runs.&lt;/P&gt;
&lt;P&gt;Either define the macro variable first.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let abc=;
%print(into=abc);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or make the macro smarter.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro print(into=);
%if not %symexist(&amp;amp;into) %then %global &amp;amp;into;
...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Second is that the INTO clause will not create (or overwrite) the target macro variable(s) if no observations are returned by the query.&amp;nbsp; To fix that you should set the macro variable to some default values before running the query.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro print(into=);
%if not %symexist(&amp;amp;into) %then %global &amp;amp;into;
%let &amp;amp;into=;
proc sql noprint;
select count(distinct USUBJID) format=32. 
  into :&amp;amp;into. separated by ' '
  from XYZ
;
quit;
%mend print;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 26 Aug 2019 18:48:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Resolving-Macro-Variable/m-p/584022#M14079</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-08-26T18:48:32Z</dc:date>
    </item>
    <item>
      <title>Re: Resolving Macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Resolving-Macro-Variable/m-p/584025#M14081</link>
      <description>Wow. It is a detailed solution. Understood where I went wrong. Thank you. Another question, if I need a result: &amp;amp;ABC. ,after resolving a macro variable print(n=ABC). How will write in program?</description>
      <pubDate>Mon, 26 Aug 2019 18:54:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Resolving-Macro-Variable/m-p/584025#M14081</guid>
      <dc:creator>Ramya2</dc:creator>
      <dc:date>2019-08-26T18:54:00Z</dc:date>
    </item>
    <item>
      <title>Re: Resolving Macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Resolving-Macro-Variable/m-p/584033#M14084</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/254855"&gt;@Ramya2&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Wow. It is a detailed solution. Understood where I went wrong. Thank you. Another question, if I need a result: &amp;amp;ABC. ,after resolving a macro variable print(n=ABC). How will write in program?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;After calling the macro with %PRINT(into=ABC) then the macro variable ABC with have the number of distinct patients in the dataset ZYX.&amp;nbsp; You can then expand the value of that macro variable by using &amp;amp;ABC anywhere you would normally type an integer.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  n_subjects = &amp;amp;abc ;
run;

%put Number of subjects in XYZ is &amp;amp;abc.. ;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Only exception is that macro triggers, &amp;amp; and %, are not evaluated inside of strings that single quotes on the outside instead of double quotes.&amp;nbsp; So check out the difference results produced by these statements.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  put "Number of subjects is &amp;amp;abc..";
  put 'Number of subjects is &amp;amp;abc..';
  put "Number of subjects is '&amp;amp;abc'.";
  put 'Number of subjects is "&amp;amp;abc".';
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 26 Aug 2019 19:05:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Resolving-Macro-Variable/m-p/584033#M14084</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-08-26T19:05:25Z</dc:date>
    </item>
  </channel>
</rss>

