<?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: symputx('items', ' leading and trailing blanks removed ', 'L') in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/symputx-items-leading-and-trailing-blanks-removed-L/m-p/849395#M335820</link>
    <description>&lt;P&gt;First question:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put local items &amp;amp;items;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;"local items" is just text which is literally written to the log. &amp;amp;items is a macro variable reference; if the variable exists, its content is placed in place of the reference.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second question:&lt;/P&gt;
&lt;P&gt;"1" is no position, it is just text stored in a macro variable.&lt;/P&gt;</description>
    <pubDate>Tue, 13 Dec 2022 12:44:39 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2022-12-13T12:44:39Z</dc:date>
    <item>
      <title>symputx('items', ' leading and trailing blanks removed ', 'L')</title>
      <link>https://communities.sas.com/t5/SAS-Programming/symputx-items-leading-and-trailing-blanks-removed-L/m-p/849231#M335748</link>
      <description>&lt;P&gt;Hello team,&lt;/P&gt;
&lt;PRE&gt;%let x=1;
%let items=2;
%macro test(val);

data _null_;
call symputx('items', ' leading and trailing blanks removed ', 'L');
call symputx(' x ', 123.456);
run;

%put local items &amp;amp;items;
%mend test;

%test(100)

%put items=!&amp;amp;items!;
%put x=!&amp;amp;x!;&lt;/PRE&gt;
&lt;P&gt;Can someone please explain about this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;call symputx('items', ' leading and trailing blanks removed ', 'L');&lt;/P&gt;
&lt;P&gt;What does this three strings passed to symputx mean?&lt;/P&gt;
&lt;P&gt;I look at the log, I am totally confused.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First, it says these two macro variables:&lt;/P&gt;
&lt;P&gt;%let x=1; %let items=2;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and then it says:&lt;/P&gt;
&lt;P&gt;call symputx('items', ' leading and trailing blanks removed ', 'L'); call symputx(' x ', 123.456);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;what does %test(100)?&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;BittenApple&lt;/P&gt;</description>
      <pubDate>Mon, 12 Dec 2022 19:25:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/symputx-items-leading-and-trailing-blanks-removed-L/m-p/849231#M335748</guid>
      <dc:creator>GN0001</dc:creator>
      <dc:date>2022-12-12T19:25:29Z</dc:date>
    </item>
    <item>
      <title>Re: symputx('items', ' leading and trailing blanks removed ', 'L')</title>
      <link>https://communities.sas.com/t5/SAS-Programming/symputx-items-leading-and-trailing-blanks-removed-L/m-p/849235#M335749</link>
      <description>&lt;P&gt;The code demonstrates the effect and use of global vs. local symbol tables.&lt;/P&gt;
&lt;P&gt;First, two macro variables are defined in the global scope.&lt;/P&gt;
&lt;P&gt;Then, a macro is defined in which a DATA step is used to call CALL SYMPUTX twice; once with the 'L' parameter, which forces the creation of a new variable with the same name in the local symbol table, and second without this parameter, which means that the global macro variable (if it already exists) will be reset with the new value.&lt;/P&gt;
&lt;P&gt;Finally, the macro is called, and the final outcome of both macro variables is displayed. Study the log closely.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For confusion, a macro parameter (val) is defined but never used.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Dec 2022 20:03:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/symputx-items-leading-and-trailing-blanks-removed-L/m-p/849235#M335749</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-12-12T20:03:58Z</dc:date>
    </item>
    <item>
      <title>Re: call symputx('items', ' leading and trailing blanks removed ', 'L');</title>
      <link>https://communities.sas.com/t5/SAS-Programming/symputx-items-leading-and-trailing-blanks-removed-L/m-p/849236#M335750</link>
      <description>&lt;P&gt;&lt;FONT face="courier new,courier"&gt;call symputx&lt;/FONT&gt; assigns the text string&amp;nbsp;'leading and trailing blanks removed' to macro variable &amp;amp;ITEMS, and the 'L' makes it a %LOCAL macro variable. Local means that the value of the macro variable is only available inside the macro that created it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Outside the macro that created it, the value inside the macro is not available and so when you try to use &amp;amp;ITEMS outside the macro, it has a different value. I leave it as a homework assignment for you to figure out why it has the value 2 outside the macro, and why the &lt;FONT face="courier new,courier"&gt;%put items=!&amp;amp;items!;&lt;/FONT&gt; produces the text string with a 2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;FONT face="courier new,courier"&gt;%test(100)&lt;/FONT&gt; executes the macro with argument 100&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Dec 2022 20:12:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/symputx-items-leading-and-trailing-blanks-removed-L/m-p/849236#M335750</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-12-12T20:12:40Z</dc:date>
    </item>
    <item>
      <title>Re: symputx('items', ' leading and trailing blanks removed ', 'L')</title>
      <link>https://communities.sas.com/t5/SAS-Programming/symputx-items-leading-and-trailing-blanks-removed-L/m-p/849237#M335751</link>
      <description>&lt;P&gt;Read the documentation first.&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.2/lefunctionsref/p1fa0ay5pzr9yun1mvqxv8ipzd4d.htm" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.2/lefunctionsref/p1fa0ay5pzr9yun1mvqxv8ipzd4d.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-SPOILER&gt;
&lt;H2 id="n0pvzh5twu8u73n1oo60a0t8b9fk" class="xisDoc-title"&gt;Syntax&lt;/H2&gt;
&lt;DIV id="n0v4zcizgxl2ddn1kjv6gtsr74zv" class="xisDoc-syntaxSimple"&gt;
&lt;DIV class="xisDoc-syntaxLevel"&gt;&lt;SPAN class="xisDoc-keyword"&gt;CALL SYMPUTX&lt;/SPAN&gt;(&lt;EM class="xisDoc-userSuppliedValue"&gt;macro-variable&lt;/EM&gt;,&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM class="xisDoc-userSuppliedValue"&gt;value&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="xisDoc-optional"&gt;&amp;lt;,&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM class="xisDoc-userSuppliedValue"&gt;symbol-table&lt;/EM&gt;&amp;gt;&lt;/SPAN&gt;);&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/LI-SPOILER&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let's re-order the statements in that code to make it more logical.&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;So first define the macro:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test(val);
data _null_;
  call symputx('items', ' leading and trailing blanks removed ', 'L');
  call symputx(' x ', 123.456);
run;
%put local items &amp;amp;items;
%mend test;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So when you call that macro it runs a data step and then issues a macro %PUT statement to write something to the SAS log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now let's look at the executable part of the code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let x=1;
%let items=2;
%test(100)
%put items=!&amp;amp;items!;
%put x=!&amp;amp;x!;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Looking at that code here is what the statements mean:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Macro variable X is set to the string 1&lt;/LI&gt;
&lt;LI&gt;Macro variable ITEMS is set to the string 2&lt;/LI&gt;
&lt;LI&gt;The macro %TEST() is called passing 100 as the single parameter value.&lt;/LI&gt;
&lt;LI&gt;It writes a string that includes the value of the ITEMS macro variable.&lt;/LI&gt;
&lt;LI&gt;It writes a string that includes the value of the X macro variable.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Now let's ask some questions.&lt;/P&gt;
&lt;P&gt;What are the differences between the two CALL SYMPUX() function calls?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-SPOILER&gt;They are writing to two different macro variables, ITEMS and X.&lt;BR /&gt;The first one adds the optional third argument 'L' which means to store the macro variable in the LOCAL symbol table&amp;nbsp;&lt;BR /&gt;The second one just uses the default setting for the third argument.&lt;/LI-SPOILER&gt;
&lt;P&gt;What impact to you expect that to have on the results shown by the last two %PUT statements?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-SPOILER&gt;The value of ITEMS has not changes, so it is still 2, but the value of X has been replaced with the string&amp;nbsp;123.456&lt;/LI-SPOILER&gt;
&lt;P&gt;Run it.&amp;nbsp; Did it produce the output you expected?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-SPOILER&gt;
&lt;PRE&gt;2263  %let x=1;
2264  %let items=2;
2265  %test(100)

NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


local items leading and trailing blanks removed
2266  %put items=!&amp;amp;items!;
items=!2!
2267  %put x=!&amp;amp;x!;
x=!123.456!
&lt;/PRE&gt;
&lt;/LI-SPOILER&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Dec 2022 20:14:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/symputx-items-leading-and-trailing-blanks-removed-L/m-p/849237#M335751</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-12-12T20:14:43Z</dc:date>
    </item>
    <item>
      <title>Re: symputx('items', ' leading and trailing blanks removed ', 'L')</title>
      <link>https://communities.sas.com/t5/SAS-Programming/symputx-items-leading-and-trailing-blanks-removed-L/m-p/849319#M335796</link>
      <description>&lt;PRE&gt;%macro test(val);
data _null_;
  call symputx('items', ' leading and trailing blanks removed ', 'L');
  call symputx(' x ', 123.456);
run;
%put local items &amp;amp;items;
%mend test;&lt;/PRE&gt;
&lt;P&gt;Why does it say items &amp;amp;items? Why does the first item stand for?&lt;/P&gt;
&lt;PRE&gt;%let x=1;
%let items=2;
%test(100)
%put items=!&amp;amp;items!;
%put x=!&amp;amp;x!;&lt;/PRE&gt;
&lt;P&gt;How do we know that 1 refers to first position of the string?&lt;/P&gt;</description>
      <pubDate>Tue, 13 Dec 2022 06:12:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/symputx-items-leading-and-trailing-blanks-removed-L/m-p/849319#M335796</guid>
      <dc:creator>GN0001</dc:creator>
      <dc:date>2022-12-13T06:12:03Z</dc:date>
    </item>
    <item>
      <title>Re: symputx('items', ' leading and trailing blanks removed ', 'L')</title>
      <link>https://communities.sas.com/t5/SAS-Programming/symputx-items-leading-and-trailing-blanks-removed-L/m-p/849395#M335820</link>
      <description>&lt;P&gt;First question:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put local items &amp;amp;items;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;"local items" is just text which is literally written to the log. &amp;amp;items is a macro variable reference; if the variable exists, its content is placed in place of the reference.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second question:&lt;/P&gt;
&lt;P&gt;"1" is no position, it is just text stored in a macro variable.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Dec 2022 12:44:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/symputx-items-leading-and-trailing-blanks-removed-L/m-p/849395#M335820</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-12-13T12:44:39Z</dc:date>
    </item>
    <item>
      <title>Re: call symputx('items', ' leading and trailing blanks removed ', 'L');</title>
      <link>https://communities.sas.com/t5/SAS-Programming/symputx-items-leading-and-trailing-blanks-removed-L/m-p/849752#M335904</link>
      <description>Hello PaigeMiller,&lt;BR /&gt;&lt;BR /&gt;Because 2 is the local and it is restricted inside the function symputx. But x is not local and  so its values is overwritten by 123.456.&lt;BR /&gt;&lt;BR /&gt;I think it should be the other way around, I mean the value of x is 123.456 should be overwritten by value X=1.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;BittenApple</description>
      <pubDate>Wed, 14 Dec 2022 22:56:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/symputx-items-leading-and-trailing-blanks-removed-L/m-p/849752#M335904</guid>
      <dc:creator>GN0001</dc:creator>
      <dc:date>2022-12-14T22:56:30Z</dc:date>
    </item>
    <item>
      <title>Re: call symputx('items', ' leading and trailing blanks removed ', 'L');</title>
      <link>https://communities.sas.com/t5/SAS-Programming/symputx-items-leading-and-trailing-blanks-removed-L/m-p/849770#M335913</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/202329"&gt;@GN0001&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Hello PaigeMiller,&lt;BR /&gt;&lt;BR /&gt;Because 2 is the local and it is restricted inside the function symputx. But x is not local and so its values is overwritten by 123.456.&lt;BR /&gt;&lt;BR /&gt;I think it should be the other way around, I mean the value of x is 123.456 should be overwritten by value X=1.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;BittenApple&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Unlike in FORTRAN in SAS macro code %LOCAL does not mean that the macro variables are restricted to just that macro.&amp;nbsp; Instead all active macro variables are available to be used and modified (except those hidden by the existence of&amp;nbsp; a macro variable with the same name in a more inner scope).&amp;nbsp; You don't use %LOCAL to protect your macro variables from other macros.&amp;nbsp; You use them to prevent your macro from causing trouble for the environments that called your macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Normally you cannot define a macro as GLOBAL if there is already one with that name that is LOCAL.&amp;nbsp; (Why would you since you could never assign it a value?)&amp;nbsp; But the "G" option of CALL SYMPUTX() allows you to by pass that restriction and push a value directly into the GLOBAL symbol table, even when there is already a LOCAL macro variable with the same name.&amp;nbsp; Of course you still cannot see the value while inside the current macro (unless you use a trick like &lt;A href="https://github.com/sasutils/macros/blob/master/symget.sas" target="_self"&gt;this %symget() function style macro&lt;/A&gt; ).&amp;nbsp; But it is useful for returning values from a macro call so that the values live on after the macro call ends.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Dec 2022 02:20:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/symputx-items-leading-and-trailing-blanks-removed-L/m-p/849770#M335913</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-12-15T02:20:30Z</dc:date>
    </item>
  </channel>
</rss>

