<?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: Tricky combination of text and macro variables in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Tricky-combination-of-text-and-macro-variables/m-p/157373#M41263</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You will have to modify your approach.&amp;nbsp; Even if you overcome this error, you will get a DATA step error.&amp;nbsp; The DATA step does not allow you to repeat the definition of the same array name.&amp;nbsp; Even these statements would generate an error if they appeared in the same DATA step:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;array array1 {23} cat_1 - cat_23;&lt;/P&gt;&lt;P&gt;array array1 {23} cat_1 - cat_23;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you were to change the second statement to use dog instead of cat, it would still generate the error.&amp;nbsp; Array names cannot be defined more than once in the same DATA step.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To answer your original question, you need to add another dot, for example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;amp;&amp;amp;prefix&amp;amp;j.._1&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The first dot delimits &amp;amp;j, the second delimits &amp;amp;prefix1/&amp;amp;prefix2.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 26 Jun 2014 19:45:27 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2014-06-26T19:45:27Z</dc:date>
    <item>
      <title>Tricky combination of text and macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Tricky-combination-of-text-and-macro-variables/m-p/157372#M41262</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hey everyone-&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm racking my brain on this one. I'm trying to use a do loop combined with arrays and macro variables to build out a dataset.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Let's assume that I have a series of cat variables (cat_1-cat_23) and dog variables (dog_1-dog_23) in my dataset that I'm attempting to manipulate in an array. I want to write a loop where the array uses the cat variables the first time through, and the dog variables the second time.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's how I'm attempting to build the code. I realize you can simplify this whole thing by attempting not to loop things, but for the more complicated application I'm attempting to use this for, looping is necessary.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let prefix1=cat;&lt;/P&gt;&lt;P&gt;%let prefix2=dog;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro catsndogs;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data rewrite;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set my_data_set;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%do j=1 %to 2;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; array array1 &lt;LI&gt; &amp;amp;&amp;amp;prefix&amp;amp;j._1-&amp;amp;&amp;amp;prefix&amp;amp;j._23; &lt;/LI&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; array array2 &lt;LI&gt; total&amp;amp;j._1- total&amp;amp;j._23;&lt;/LI&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; do i=1 to 23; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; array2&lt;J&gt;=array[1]-5;&lt;/J&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;%catsndogs;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;My instinct is that the first time through it would resolve things like this:&lt;/P&gt;&lt;P&gt;&amp;amp;&amp;amp;prefix&amp;amp;j._1 = &amp;amp;prefix1._1 =&amp;nbsp; cat_1&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Instead, it resolves like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;amp;&amp;amp;prefix&amp;amp;j._1 = &amp;amp;prefix1_1 = This doesn't exist, so it bombs out.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How can I rig the syntax so that the syntax resolves to array array1 &lt;LI&gt; cat_1-cat_23 the first time, and array1&lt;/LI&gt;&lt;LI&gt; dog_1-dog_23 the second time?&lt;/LI&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 Jun 2014 19:36:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Tricky-combination-of-text-and-macro-variables/m-p/157372#M41262</guid>
      <dc:creator>keeks137</dc:creator>
      <dc:date>2014-06-26T19:36:58Z</dc:date>
    </item>
    <item>
      <title>Re: Tricky combination of text and macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Tricky-combination-of-text-and-macro-variables/m-p/157373#M41263</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You will have to modify your approach.&amp;nbsp; Even if you overcome this error, you will get a DATA step error.&amp;nbsp; The DATA step does not allow you to repeat the definition of the same array name.&amp;nbsp; Even these statements would generate an error if they appeared in the same DATA step:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;array array1 {23} cat_1 - cat_23;&lt;/P&gt;&lt;P&gt;array array1 {23} cat_1 - cat_23;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you were to change the second statement to use dog instead of cat, it would still generate the error.&amp;nbsp; Array names cannot be defined more than once in the same DATA step.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To answer your original question, you need to add another dot, for example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;amp;&amp;amp;prefix&amp;amp;j.._1&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The first dot delimits &amp;amp;j, the second delimits &amp;amp;prefix1/&amp;amp;prefix2.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 Jun 2014 19:45:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Tricky-combination-of-text-and-macro-variables/m-p/157373#M41263</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2014-06-26T19:45:27Z</dc:date>
    </item>
    <item>
      <title>Re: Tricky combination of text and macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Tricky-combination-of-text-and-macro-variables/m-p/157374#M41264</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think I just got it to work actually with the addition of the second period, so thanks much for that!!!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'll be back to post my full code as soon as I get a moment, to show you the more complicated version. I'll also make sure it's working as I would expect.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks again!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 Jun 2014 20:01:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Tricky-combination-of-text-and-macro-variables/m-p/157374#M41264</guid>
      <dc:creator>keeks137</dc:creator>
      <dc:date>2014-06-26T20:01:15Z</dc:date>
    </item>
    <item>
      <title>Re: Tricky combination of text and macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Tricky-combination-of-text-and-macro-variables/m-p/157375#M41265</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Consider defining a two dimensional array instead of 1?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then use the j as the index for the second dimension?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 Jun 2014 20:14:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Tricky-combination-of-text-and-macro-variables/m-p/157375#M41265</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2014-06-26T20:14:11Z</dc:date>
    </item>
    <item>
      <title>Re: Tricky combination of text and macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Tricky-combination-of-text-and-macro-variables/m-p/157376#M41266</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'll look into this tomorrow.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for your help!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 Jun 2014 21:01:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Tricky-combination-of-text-and-macro-variables/m-p/157376#M41266</guid>
      <dc:creator>keeks137</dc:creator>
      <dc:date>2014-06-26T21:01:42Z</dc:date>
    </item>
    <item>
      <title>Re: Tricky combination of text and macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Tricky-combination-of-text-and-macro-variables/m-p/157377#M41267</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I eventually ended up creating multiple datasets within the loop, and then merged them together. Here's the code I used:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let groups=5; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let pre1=cta;&lt;/P&gt;&lt;P&gt;%let qs1=23;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let pre2=ctb;&lt;/P&gt;&lt;P&gt;%let qs2=18;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let pre3=ctc;&lt;/P&gt;&lt;P&gt;%let qs3=4;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let pre4=cm2;&lt;/P&gt;&lt;P&gt;%let qs4=24;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let pre5=cf5;&lt;/P&gt;&lt;P&gt;%let qs5=13;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro profile;&lt;/P&gt;&lt;P&gt;%do j=1 %to &amp;amp;groups;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data rewrite&amp;amp;j (keep=occasions &amp;amp;&amp;amp;pre&amp;amp;j.._1-&amp;amp;&amp;amp;pre&amp;amp;j.._&amp;amp;&amp;amp;qs&amp;amp;j t_&amp;amp;&amp;amp;pre&amp;amp;j.._1-t_&amp;amp;&amp;amp;pre&amp;amp;j.._&amp;amp;&amp;amp;qs&amp;amp;j);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; set step1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; array array1 &lt;LI&gt; &amp;amp;&amp;amp;pre&amp;amp;j.._1-&amp;amp;&amp;amp;pre&amp;amp;j.._&amp;amp;&amp;amp;qs&amp;amp;j;&lt;/LI&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; array array2 &lt;LI&gt; t_&amp;amp;&amp;amp;pre&amp;amp;j.._1-t_&amp;amp;&amp;amp;pre&amp;amp;j.._&amp;amp;&amp;amp;qs&amp;amp;j;&lt;/LI&gt;&lt;/P&gt;&lt;P&gt;do i=1 to &amp;amp;&amp;amp;qs&amp;amp;j;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; if array1&lt;I&gt; = 5 then array2&lt;I&gt;=1;&lt;/I&gt;&lt;/I&gt;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort data=rewrite&amp;amp;j; by occasions; run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;%profile;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data final_rewrite;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; merge rewrite1-rewrite&amp;amp;groups;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; by occasions;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What the code does is it loops through 5 times and creates five datasets. Each new dataset creates a new array of variables. I used the %pre type variables to indicate what the prefix of the variable names are, and the %qs variables to indicate how many questions there were that used that prefix. So, the first time through, it manipulates cta_1-cta_23. After the loop is done, it merges all of the information together so that I have everything in a single dataset.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks to Astounding's advice, I got the macro variables to resolve properly, and after that it was just a matter of figuring out how I could include array statements in a loop, since you can't utilize something like "array1" twice.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you everyone!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 27 Jun 2014 18:21:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Tricky-combination-of-text-and-macro-variables/m-p/157377#M41267</guid>
      <dc:creator>keeks137</dc:creator>
      <dc:date>2014-06-27T18:21:26Z</dc:date>
    </item>
  </channel>
</rss>

