<?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: Using a macro variable to name a datastep in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-a-macro-variable-to-name-a-datastep/m-p/252402#M47878</link>
    <description>&lt;P&gt;Try&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;call symput ('id', put(id,z6.));
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;with&amp;nbsp;&lt;SPAN&gt;run_&amp;amp;id&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 25 Feb 2016 16:14:35 GMT</pubDate>
    <dc:creator>mohamed_zaki</dc:creator>
    <dc:date>2016-02-25T16:14:35Z</dc:date>
    <item>
      <title>Using a macro variable to name a datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-macro-variable-to-name-a-datastep/m-p/252394#M47876</link>
      <description>&lt;PRE&gt;    data table;
        format id ser;
        input id ser;
		datalines;
        1 12345
        2 06789
        ;
    run;
    data names(keep = id);
        set table;
    run;
    data _null_;
       set names nobs = n;
       call symput ('cnt', n);
    run;
    %macro test;
    %do i = 1 %to &amp;amp;cnt;
        data first;
            set names (obs = 1);
        run;
		data _null_;
			set first;
			call symput ('id', trim(id));
		run;
        data run_"&amp;amp;id";
            set table;
			addone = &amp;amp;id + 1;
        run;
		data names;
			set names (firstobs = 2);
		run;
    %end;
    %mend test;
    %test;&lt;/PRE&gt;&lt;P&gt;When I execute this SAS program, I get:&lt;/P&gt;&lt;PRE&gt;ERROR: The value '2'n is not a valid SAS name.&lt;/PRE&gt;&lt;P&gt;I tried run_"&amp;amp;id", run_'&amp;amp;id', run_&amp;amp;id, and options validvarname = any but nothing seems to quell the problem. What can I do?&lt;/P&gt;</description>
      <pubDate>Thu, 25 Feb 2016 15:35:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-macro-variable-to-name-a-datastep/m-p/252394#M47876</guid>
      <dc:creator>dwsmith</dc:creator>
      <dc:date>2016-02-25T15:35:00Z</dc:date>
    </item>
    <item>
      <title>Re: Using a macro variable to name a datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-macro-variable-to-name-a-datastep/m-p/252402#M47878</link>
      <description>&lt;P&gt;Try&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;call symput ('id', put(id,z6.));
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;with&amp;nbsp;&lt;SPAN&gt;run_&amp;amp;id&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Feb 2016 16:14:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-macro-variable-to-name-a-datastep/m-p/252402#M47878</guid>
      <dc:creator>mohamed_zaki</dc:creator>
      <dc:date>2016-02-25T16:14:35Z</dc:date>
    </item>
    <item>
      <title>Re: Using a macro variable to name a datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-macro-variable-to-name-a-datastep/m-p/252403#M47879</link>
      <description>&lt;P&gt;Remove the quotes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data run_&amp;amp;id;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 25 Feb 2016 16:01:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-macro-variable-to-name-a-datastep/m-p/252403#M47879</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-02-25T16:01:02Z</dc:date>
    </item>
    <item>
      <title>Re: Using a macro variable to name a datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-macro-variable-to-name-a-datastep/m-p/252404#M47880</link>
      <description>&lt;P&gt;Remove the quotes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data run_&amp;amp;id;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 25 Feb 2016 16:01:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-macro-variable-to-name-a-datastep/m-p/252404#M47880</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-02-25T16:01:04Z</dc:date>
    </item>
    <item>
      <title>Re: Using a macro variable to name a datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-macro-variable-to-name-a-datastep/m-p/252405#M47881</link>
      <description>&lt;P&gt;Removing the quotes produces:&lt;/P&gt;&lt;PRE&gt;NOTE: Line generated by the macro variable "ID".
1      run_           2
                      -
                      22
                      200

ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, (, /, ;, _DATA_,
              _LAST_, _NULL_.

ERROR 200-322: The symbol is not recognized and will be ignored.&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Feb 2016 16:02:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-macro-variable-to-name-a-datastep/m-p/252405#M47881</guid>
      <dc:creator>dwsmith</dc:creator>
      <dc:date>2016-02-25T16:02:53Z</dc:date>
    </item>
    <item>
      <title>Re: Using a macro variable to name a datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-macro-variable-to-name-a-datastep/m-p/252406#M47882</link>
      <description>&lt;P&gt;As others have indicated, you do need to remove the double quotes.&amp;nbsp; But there is more that can be cleaned up here.&amp;nbsp; Try it this way:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro test;&lt;/P&gt;
&lt;P&gt;%local i id;&lt;/P&gt;
&lt;P&gt;%do i=1 %to &amp;amp;cnt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; data _null_;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; set names (obs=&amp;amp;i firstobs=&amp;amp;i);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; call symputx('id', id);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; data run_&amp;amp;id;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; set table;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; addone = &amp;amp;id + 1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; run;&lt;/P&gt;
&lt;P&gt;%end;&lt;/P&gt;
&lt;P&gt;%mend test;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note:&amp;nbsp; Added the %end statement.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Feb 2016 16:08:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-macro-variable-to-name-a-datastep/m-p/252406#M47882</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-02-25T16:08:43Z</dc:date>
    </item>
    <item>
      <title>Re: Using a macro variable to name a datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-macro-variable-to-name-a-datastep/m-p/252408#M47883</link>
      <description>&lt;P&gt;I dont understand. Why would you change the name to idd and then use run_id with only one d?&lt;/P&gt;</description>
      <pubDate>Thu, 25 Feb 2016 16:04:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-macro-variable-to-name-a-datastep/m-p/252408#M47883</guid>
      <dc:creator>dwsmith</dc:creator>
      <dc:date>2016-02-25T16:04:44Z</dc:date>
    </item>
    <item>
      <title>Re: Using a macro variable to name a datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-macro-variable-to-name-a-datastep/m-p/252410#M47885</link>
      <description>&lt;P&gt;Replace all of your 'call symput' with 'call symputx', the latter removes&amp;nbsp;blanks when dealing with numbers.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Feb 2016 16:06:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-macro-variable-to-name-a-datastep/m-p/252410#M47885</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2016-02-25T16:06:58Z</dc:date>
    </item>
    <item>
      <title>Re: Using a macro variable to name a datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-macro-variable-to-name-a-datastep/m-p/252412#M47887</link>
      <description>&lt;P&gt;Using symputx, still produces the same problem.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Feb 2016 16:08:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-macro-variable-to-name-a-datastep/m-p/252412#M47887</guid>
      <dc:creator>dwsmith</dc:creator>
      <dc:date>2016-02-25T16:08:35Z</dc:date>
    </item>
    <item>
      <title>Re: Using a macro variable to name a datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-macro-variable-to-name-a-datastep/m-p/252415#M47889</link>
      <description>&lt;P&gt;It is just typo... sorry&lt;/P&gt;</description>
      <pubDate>Thu, 25 Feb 2016 16:14:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-macro-variable-to-name-a-datastep/m-p/252415#M47889</guid>
      <dc:creator>mohamed_zaki</dc:creator>
      <dc:date>2016-02-25T16:14:06Z</dc:date>
    </item>
    <item>
      <title>Re: Using a macro variable to name a datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-macro-variable-to-name-a-datastep/m-p/252422#M47894</link>
      <description>&lt;P&gt;Try this (tested):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;data _null_;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;set first;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;call symput ('id', &lt;STRONG&gt;left(id)&lt;/STRONG&gt;);&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;run;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;data &lt;STRONG&gt;run_&amp;amp;id&lt;/STRONG&gt;;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;set table;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;addone = &amp;amp;id + 1;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;run;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;LEFT returns a character string with leading blanks moved to the end of the value.&lt;/P&gt;&lt;P&gt;TRIM removes trailing blanks.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Feb 2016 16:33:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-macro-variable-to-name-a-datastep/m-p/252422#M47894</guid>
      <dc:creator>lxn1021</dc:creator>
      <dc:date>2016-02-25T16:33:35Z</dc:date>
    </item>
  </channel>
</rss>

