<?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 Using numeric macro variable  within character values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-numeric-macro-variable-within-character-values/m-p/421664#M103711</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have several datasets named like file_1, file_2, ..., file_20. I need to define a variable named&amp;nbsp;&lt;EM&gt;model&lt;/EM&gt;&amp;nbsp;in each dataset with the value of &lt;EM&gt;model_i&lt;/EM&gt;, in which i represents the number associated with each file. For example, I need to have model=model_1; in file_1 dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried the following code, but it doesn't work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro modeltype;&lt;/P&gt;&lt;P&gt;%do i=1 %to 20;&lt;/P&gt;&lt;P&gt;data file_&amp;amp;i;&lt;/P&gt;&lt;P&gt;set file_&amp;amp;i;&lt;/P&gt;&lt;P&gt;model="model_&amp;amp;i";&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;%modeltype;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I appreciate any suggestion to fix this code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 15 Dec 2017 17:49:06 GMT</pubDate>
    <dc:creator>DavyJones</dc:creator>
    <dc:date>2017-12-15T17:49:06Z</dc:date>
    <item>
      <title>Using numeric macro variable  within character values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-numeric-macro-variable-within-character-values/m-p/421664#M103711</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have several datasets named like file_1, file_2, ..., file_20. I need to define a variable named&amp;nbsp;&lt;EM&gt;model&lt;/EM&gt;&amp;nbsp;in each dataset with the value of &lt;EM&gt;model_i&lt;/EM&gt;, in which i represents the number associated with each file. For example, I need to have model=model_1; in file_1 dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried the following code, but it doesn't work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro modeltype;&lt;/P&gt;&lt;P&gt;%do i=1 %to 20;&lt;/P&gt;&lt;P&gt;data file_&amp;amp;i;&lt;/P&gt;&lt;P&gt;set file_&amp;amp;i;&lt;/P&gt;&lt;P&gt;model="model_&amp;amp;i";&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;%modeltype;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I appreciate any suggestion to fix this code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Dec 2017 17:49:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-numeric-macro-variable-within-character-values/m-p/421664#M103711</guid>
      <dc:creator>DavyJones</dc:creator>
      <dc:date>2017-12-15T17:49:06Z</dc:date>
    </item>
    <item>
      <title>Re: Using numeric macro variable  within character values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-numeric-macro-variable-within-character-values/m-p/421667#M103712</link>
      <description>&lt;P&gt;With a small change your code should be fine.&amp;nbsp; Add this line before the SET statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;length model $ 8;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That way, if you ever combine the files, you will have MODEL defined the same way in all files.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now you didn't really say with "didn't work" means.&amp;nbsp; So if there's some other problem, you might have to provide a detail or two.&amp;nbsp; For example, perhaps MODEL already exists in the incoming files, possibly as a numeric variable.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Dec 2017 17:56:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-numeric-macro-variable-within-character-values/m-p/421667#M103712</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-12-15T17:56:58Z</dc:date>
    </item>
    <item>
      <title>Re: Using numeric macro variable  within character values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-numeric-macro-variable-within-character-values/m-p/421669#M103713</link>
      <description>Thanks. After specifying the length, the variable was properly defined.</description>
      <pubDate>Fri, 15 Dec 2017 18:11:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-numeric-macro-variable-within-character-values/m-p/421669#M103713</guid>
      <dc:creator>DavyJones</dc:creator>
      <dc:date>2017-12-15T18:11:27Z</dc:date>
    </item>
  </channel>
</rss>

