<?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: Can macro variables created in select into be local? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Can-macro-variables-created-in-select-into-be-local/m-p/83856#M18106</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;not sure why I feel I have to add this , but ... since no-one has pointed it out&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If your macro invokes SELECT&amp;nbsp; ....... INTO :mac_var1&lt;/P&gt;&lt;P&gt;then it might not be as _local_ as you expected&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro do_it( variable, data= sashelp.class ) ;&lt;BR /&gt;proc sql noprint ;&lt;BR /&gt;select max(&amp;amp;variable) into :mac_&amp;amp;variable&amp;nbsp; from &amp;amp;data ;&lt;BR /&gt;quit ;&lt;BR /&gt;%put _user_ ;&lt;BR /&gt;%mend&amp;nbsp; do_it ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro caller ;&lt;BR /&gt; %let mac_age = 1 ;&lt;BR /&gt; %do_it( age ) ;&lt;BR /&gt; %do_it( height ) ;&lt;BR /&gt;%mend&amp;nbsp; caller ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;option mprint ;&lt;/P&gt;&lt;P&gt;%caller&lt;BR /&gt;%put _user_;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;macro variables mac_age and mac_height are not global&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;but mac_age is not local to %do_it&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 15 Apr 2012 15:46:37 GMT</pubDate>
    <dc:creator>Peter_C</dc:creator>
    <dc:date>2012-04-15T15:46:37Z</dc:date>
    <item>
      <title>Can macro variables created in select into be local?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-macro-variables-created-in-select-into-be-local/m-p/83853#M18103</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Can macro variables created in select into be local?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL style="list-style-type: disc;"&gt;&lt;LI&gt;&lt;SPAN style="font-size: 10pt; font-family: NewCenturySchlbk-Roman;"&gt;SELECT … INTO :mac_var1&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: NewCenturySchlbk-Roman;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: NewCenturySchlbk-Roman;"&gt;will mac_var1 be local?&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 14 Apr 2012 17:27:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-macro-variables-created-in-select-into-be-local/m-p/83853#M18103</guid>
      <dc:creator>ZRick</dc:creator>
      <dc:date>2012-04-14T17:27:09Z</dc:date>
    </item>
    <item>
      <title>Re: Can macro variables created in select into be local?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-macro-variables-created-in-select-into-be-local/m-p/83854#M18104</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you are inside of a macro AND if the macro variables have not defined before then they will be local.&amp;nbsp; But if the macro variables already existing (either global or local) then the existing macro variable will get the value.&lt;/P&gt;&lt;P&gt;In this example VAR1 will be GLOBAL, VAR2 will be local with scope of macro OUTER. The other macro variables will be local with scope of the macro INNER.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%let var1=global;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%macro inner;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;proc sql noprint ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; select name into :var1-:var100 from sashelp.class ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%put _user_;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%mend inner;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%macro outer ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; %local var2;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; %inner;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%mend outer;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%outer;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 14 Apr 2012 18:38:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-macro-variables-created-in-select-into-be-local/m-p/83854#M18104</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2012-04-14T18:38:45Z</dc:date>
    </item>
    <item>
      <title>Re: Can macro variables created in select into be local?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-macro-variables-created-in-select-into-be-local/m-p/83855#M18105</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;Hi:&lt;/P&gt;&lt;P&gt;&amp;nbsp; It sort of depends. You can run the code below and review what you see in the SAS log. The macro variable HOWOLD created out in "open code" is global in scope by default. A "local" symbol table only exists for the duration of a macro program. For example, if you are just running PROC SQL and no macro program is involved, then there is no local table, only the global table. So you couldn't put a macro variable into the local table if it doesn't exist. On the other hand, if you create a macro variable INSIDE a macro program, unless you explicitly put the macro variable into the global table, it will be local in scope. The rules of global and local scope are outlined very nicely in the macro documentation and the %GLOBAL and %LOCAL statements exist to help you declare scope if you explicitly need to. In addition, CALL SYMPUTX allows you to specify the global or local placement of a macro variable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; cynthia&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;proc sql;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;&amp;nbsp; select age into :howold&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;&amp;nbsp; from sashelp.class&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;&amp;nbsp; where name="Philip";&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;quit;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;%put ---- INTO in open code, not in macro program;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;%put _user_;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;%macro findage(want=);&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;proc sql;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;&amp;nbsp; select age into :theage&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;&amp;nbsp; from sashelp.class&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;&amp;nbsp; where name="&amp;amp;want";&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;quit;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;%global gmvar;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;%local lmvar;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;data _null_;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;&amp;nbsp; call symputx('gmvar','This one is GLOBAL',G);&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;&amp;nbsp; call symputx('lmvar','This one is LOCAL',L);&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;%put _user_;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;%mend findage;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;options mlogic;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;%findage(want=Philip)&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;%findage(want=Alfred)&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;options nomlogic;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;%put after running macro;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;%put _user_;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 14 Apr 2012 18:42:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-macro-variables-created-in-select-into-be-local/m-p/83855#M18105</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2012-04-14T18:42:48Z</dc:date>
    </item>
    <item>
      <title>Re: Can macro variables created in select into be local?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-macro-variables-created-in-select-into-be-local/m-p/83856#M18106</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;not sure why I feel I have to add this , but ... since no-one has pointed it out&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If your macro invokes SELECT&amp;nbsp; ....... INTO :mac_var1&lt;/P&gt;&lt;P&gt;then it might not be as _local_ as you expected&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro do_it( variable, data= sashelp.class ) ;&lt;BR /&gt;proc sql noprint ;&lt;BR /&gt;select max(&amp;amp;variable) into :mac_&amp;amp;variable&amp;nbsp; from &amp;amp;data ;&lt;BR /&gt;quit ;&lt;BR /&gt;%put _user_ ;&lt;BR /&gt;%mend&amp;nbsp; do_it ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro caller ;&lt;BR /&gt; %let mac_age = 1 ;&lt;BR /&gt; %do_it( age ) ;&lt;BR /&gt; %do_it( height ) ;&lt;BR /&gt;%mend&amp;nbsp; caller ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;option mprint ;&lt;/P&gt;&lt;P&gt;%caller&lt;BR /&gt;%put _user_;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;macro variables mac_age and mac_height are not global&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;but mac_age is not local to %do_it&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 15 Apr 2012 15:46:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-macro-variables-created-in-select-into-be-local/m-p/83856#M18106</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2012-04-15T15:46:37Z</dc:date>
    </item>
  </channel>
</rss>

