<?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: How to remove the space for Macro N? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-the-space-for-Macro-N/m-p/371271#M275871</link>
    <description>&lt;P&gt;If you have 207 macro variables, you probably got them by looping through 207 SELECT statements.&amp;nbsp; Just make the %LET statement part of the macro that contains the SELECT statement.&amp;nbsp; Since %LET can go before the QUIT statement that ends PROC SQL, this should be relatively straightforward but you can always post the macro if you need help with that.&lt;/P&gt;</description>
    <pubDate>Wed, 28 Jun 2017 13:07:19 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2017-06-28T13:07:19Z</dc:date>
    <item>
      <title>How to remove the space for Macro N?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-the-space-for-Macro-N/m-p/371257#M275868</link>
      <description>&lt;P&gt;Hello:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I&amp;nbsp; have the following program.&amp;nbsp; I found the &amp;amp;N207 came with space and couldn't be recoganized.&amp;nbsp;&amp;nbsp; How to remove the space of N207?&amp;nbsp; I have 200 macro N, I prefer not doing this one by one.&amp;nbsp; Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;proc SQL;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;Select&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; sum(&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;case&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;when&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; find (name, &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'nad_dx'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; )&amp;gt;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;then&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;else&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;end&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;into&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;: N207 &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;FROM&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; &amp;amp;State.name;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;quit&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;data want;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;set have (keep=nad_dx_&amp;amp;N207);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;run;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SYMBOLGEN: Macro variable N207 resolves to&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 32&lt;/P&gt;&lt;P&gt;ERROR: nad_dx_ does not have a numeric suffix.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jun 2017 12:40:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-the-space-for-Macro-N/m-p/371257#M275868</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2017-06-28T12:40:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove the space for Macro N?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-the-space-for-Macro-N/m-p/371259#M275869</link>
      <description>&lt;P&gt;Either before or after the QUIT statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let n207 = &amp;amp;n207;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This generates leading blanks to the right of the equal sign, but %LET ignores those leading blanks.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jun 2017 12:43:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-the-space-for-Macro-N/m-p/371259#M275869</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-06-28T12:43:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove the space for Macro N?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-the-space-for-Macro-N/m-p/371266#M275870</link>
      <description>&lt;P&gt;So if I have 207 macro N, could I do the following?&amp;nbsp; Or I have to list them one by one?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let n1-n207 = &amp;amp;n201-&amp;nbsp;&amp;amp;n207;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jun 2017 13:00:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-the-space-for-Macro-N/m-p/371266#M275870</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2017-06-28T13:00:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove the space for Macro N?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-the-space-for-Macro-N/m-p/371271#M275871</link>
      <description>&lt;P&gt;If you have 207 macro variables, you probably got them by looping through 207 SELECT statements.&amp;nbsp; Just make the %LET statement part of the macro that contains the SELECT statement.&amp;nbsp; Since %LET can go before the QUIT statement that ends PROC SQL, this should be relatively straightforward but you can always post the macro if you need help with that.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jun 2017 13:07:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-the-space-for-Macro-N/m-p/371271#M275871</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-06-28T13:07:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove the space for Macro N?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-the-space-for-Macro-N/m-p/371278#M275872</link>
      <description>&lt;P&gt;Could you show me more&amp;nbsp;details how to do it?&amp;nbsp; Thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jun 2017 13:13:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-the-space-for-Macro-N/m-p/371278#M275872</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2017-06-28T13:13:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove the space for Macro N?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-the-space-for-Macro-N/m-p/371279#M275873</link>
      <description>&lt;P&gt;207 (two-hundred-and-seven) macro variables? Madness. Stark raving madness. Keep your data in datasets.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jun 2017 13:16:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-the-space-for-Macro-N/m-p/371279#M275873</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-06-28T13:16:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove the space for Macro N?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-the-space-for-Macro-N/m-p/371284#M275874</link>
      <description>&lt;P&gt;If the SELECT statement is in a macro loop, it would look like this (in simplified form):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%do i=1 %to &amp;amp;n;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; select ... into : N&amp;amp;i;&lt;/P&gt;
&lt;P&gt;%end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If that's the case, you could always change that code to:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%do i=1 %to &amp;amp;n;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; select ... into : N&amp;amp;i;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; %let n&amp;amp;i = &amp;amp;&amp;amp;n&amp;amp;i;&lt;/P&gt;
&lt;P&gt;%end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Alternatively if you are just trying to handle 207 macro variables after the fact, embed this code in a macro:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%do i=1 %to 207;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; %let n&amp;amp;i = &amp;amp;&amp;amp;n&amp;amp;i;&lt;/P&gt;
&lt;P&gt;%end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This has to go inside a macro because %DO is not permitted outside of a macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jun 2017 13:22:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-the-space-for-Macro-N/m-p/371284#M275874</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-06-28T13:22:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove the space for Macro N?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-the-space-for-Macro-N/m-p/371294#M275875</link>
      <description>Select sum(case when find (name, 'nad_dx' )&amp;gt;0 then 1 else 0 end) into: N207          separated by ' '</description>
      <pubDate>Wed, 28 Jun 2017 13:38:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-the-space-for-Macro-N/m-p/371294#M275875</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-06-28T13:38:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove the space for Macro N?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-the-space-for-Macro-N/m-p/371300#M275876</link>
      <description>&lt;P&gt;First thing is to not add the spaces to begin with use the TRIMMED keyword in the select. Or if you are running a really old version of SAS use SEPARATED BY &amp;nbsp;' ' instead.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select count(*) into :N trimmed from ....&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Second is add a step to re-assign the macro variable value to itself as this will remove leading/trailing spaces.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let n=&amp;amp;n;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or third since your value is an integer you can use %EVAL() where you reference the value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have (keep=nad_dx_%eval(&amp;amp;N207));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Jun 2017 13:48:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-the-space-for-Macro-N/m-p/371300#M275876</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-06-28T13:48:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove the space for Macro N?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-the-space-for-Macro-N/m-p/371342#M275877</link>
      <description>&lt;P&gt;Thanks for all of your great help.&amp;nbsp; I wish I could do multipul 'accept solution'.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jun 2017 15:13:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-the-space-for-Macro-N/m-p/371342#M275877</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2017-06-28T15:13:23Z</dc:date>
    </item>
  </channel>
</rss>

