<?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: why are my macros resolving with blank spaces preceding them? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/why-are-my-macros-resolving-with-blank-spaces-preceding-them/m-p/788999#M252410</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/350407"&gt;@EC27556&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I actually created a range of 'test' macros using the old symput from the TEST.TEST data table:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data _NULL_;
set Test.Test nobs=TEST_TOT;
call symput ('Test'||left(put(_n_,3.)),test);
call symput ('TEST_TOT',TEST_TOT);
run;&lt;/PRE&gt;
&lt;P&gt;if i were to use symputx would the test variables resolve correctly then?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have also worked out i can put in a %trim function to fix too!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT size="5" color="#FF0000"&gt;&lt;STRONG&gt;TEST IT!&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="4" color="#000000"&gt;It is so hard to do:&lt;BR /&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;PRE&gt;data test;
   test=4;
run;

data _null_;
set test;
call symput ('Test1',test);
call symputx ('Test2',test);
run;

%put test1 is:|&amp;amp;test1.|;
%put test2 is:|&amp;amp;test2.|;&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;FONT size="4" color="#000000"&gt;Note: without a very clear definition of "resolve correctly" I won't say that it will. &lt;/FONT&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 07 Jan 2022 23:43:57 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2022-01-07T23:43:57Z</dc:date>
    <item>
      <title>why are my macros resolving with blank spaces preceding them?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-are-my-macros-resolving-with-blank-spaces-preceding-them/m-p/788935#M252376</link>
      <description>&lt;P&gt;See the below, I have a macro that exists that equals "1". Therefore, when I run the below I expect to see test="alpha1" in the created dataset. Instead I get "alpha&amp;nbsp; &amp;nbsp; 1". Why is this, and is there any way to get rid of these blank spaces between alpha and 1?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data test;
test="alpha&amp;amp;test1";
run;&lt;/PRE&gt;</description>
      <pubDate>Fri, 07 Jan 2022 18:12:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-are-my-macros-resolving-with-blank-spaces-preceding-them/m-p/788935#M252376</guid>
      <dc:creator>EC27556</dc:creator>
      <dc:date>2022-01-07T18:12:04Z</dc:date>
    </item>
    <item>
      <title>Re: why are my macros resolving with blank spaces preceding them?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-are-my-macros-resolving-with-blank-spaces-preceding-them/m-p/788937#M252378</link>
      <description>&lt;P&gt;Check what value it actually has by running something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put |&amp;amp;test1|;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;One easy way to remove them is it just use a %LET to recreate the macro varaible.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let test1=&amp;amp;test1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You did not show how you created TEST1.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here are two mistakes users can make that lead to leading spaces in macro variables.&lt;/P&gt;
&lt;P&gt;1) Using the ancient CALL SYMPUT() function instead of the modern CALL SYMPUTX().&lt;/P&gt;
&lt;P&gt;2) Using the INTO clause in SQL without using the TRIMMED keyword.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  num=1;
  string='   1';
  call symput('bad1',num);
  call symputx('good1',num);
  call symput('bad2',string);
  call symputx('good2',string);
run;
proc sql noprint;
  select num,num,string,string
    into :bad3
       , :good3 trimmed
       , :bad4 
       , :good4 trimmed
    from test
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;604   %put |&amp;amp;good1| |&amp;amp;bad1| ;
|1| |           1|
605   %put |&amp;amp;good2| |&amp;amp;bad2| ;
|1| |   1|
606   %put |&amp;amp;good3| |&amp;amp;bad3| ;
|1| |       1|
607   %put |&amp;amp;good4| |&amp;amp;bad4| ;
|1| |   1|

&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jan 2022 18:20:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-are-my-macros-resolving-with-blank-spaces-preceding-them/m-p/788937#M252378</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-01-07T18:20:59Z</dc:date>
    </item>
    <item>
      <title>Re: why are my macros resolving with blank spaces preceding them?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-are-my-macros-resolving-with-blank-spaces-preceding-them/m-p/788941#M252380</link>
      <description>&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I actually created a range of 'test' macros using the old symput from the TEST.TEST data table:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data _NULL_;
set Test.Test nobs=TEST_TOT;
call symput ('Test'||left(put(_n_,3.)),test);
call symput ('TEST_TOT',TEST_TOT);
run;&lt;/PRE&gt;
&lt;P&gt;if i were to use symputx would the test variables resolve correctly then?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have also worked out i can put in a %trim function to fix too!&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jan 2022 19:17:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-are-my-macros-resolving-with-blank-spaces-preceding-them/m-p/788941#M252380</guid>
      <dc:creator>EC27556</dc:creator>
      <dc:date>2022-01-07T19:17:03Z</dc:date>
    </item>
    <item>
      <title>Re: why are my macros resolving with blank spaces preceding them?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-are-my-macros-resolving-with-blank-spaces-preceding-them/m-p/788963#M252385</link>
      <description>&lt;P&gt;Use modern techniques.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _NULL_;
  if eof then call symputx('TEST_TOT',TEST_TOT);
  set Test.Test end=eof nobs=TEST_TOT;
  call symputx(cats('Test',_n_),test);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But I always wonder what value is gained by extracting data from datasets and stuffing it into so many macro variables.&lt;/P&gt;
&lt;P&gt;If you want to use it generate code then use the data step to generate the code and leave the data in the dataset.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jan 2022 21:21:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-are-my-macros-resolving-with-blank-spaces-preceding-them/m-p/788963#M252385</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-01-07T21:21:01Z</dc:date>
    </item>
    <item>
      <title>Re: why are my macros resolving with blank spaces preceding them?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-are-my-macros-resolving-with-blank-spaces-preceding-them/m-p/788999#M252410</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/350407"&gt;@EC27556&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I actually created a range of 'test' macros using the old symput from the TEST.TEST data table:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data _NULL_;
set Test.Test nobs=TEST_TOT;
call symput ('Test'||left(put(_n_,3.)),test);
call symput ('TEST_TOT',TEST_TOT);
run;&lt;/PRE&gt;
&lt;P&gt;if i were to use symputx would the test variables resolve correctly then?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have also worked out i can put in a %trim function to fix too!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT size="5" color="#FF0000"&gt;&lt;STRONG&gt;TEST IT!&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="4" color="#000000"&gt;It is so hard to do:&lt;BR /&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;PRE&gt;data test;
   test=4;
run;

data _null_;
set test;
call symput ('Test1',test);
call symputx ('Test2',test);
run;

%put test1 is:|&amp;amp;test1.|;
%put test2 is:|&amp;amp;test2.|;&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;FONT size="4" color="#000000"&gt;Note: without a very clear definition of "resolve correctly" I won't say that it will. &lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jan 2022 23:43:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-are-my-macros-resolving-with-blank-spaces-preceding-them/m-p/788999#M252410</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-01-07T23:43:57Z</dc:date>
    </item>
  </channel>
</rss>

