<?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 How do i create a series of macro variables using an array and do loop? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-create-a-series-of-macro-variables-using-an-array-and/m-p/853449#M337324</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is a data manipulation exercise. I'm trying to use the following data to macrotize the values in 4 out of the 5 variables. I'm new to the arrays, but i'm not sure what i'm doing wrong.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the data:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have; 
infile datalines dsd dlm=",";
	input word1 $ word2 $ word3$ word4$ word5$;
datalines;
We, are, here, now., pretzel
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;My code doesn't work. I want to only macrotize the the values from word1 to word4. Thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_; set have;

array word[4] word1--word4;
do i=1 to 4;

	call symput('word[i]', word[i]);
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The desired outcome:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to create 4 macro variables that are named the following, "word1", "word2", "word3", "word4", using only the variables word1, word2, word3, word4&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Thu, 12 Jan 2023 14:27:27 GMT</pubDate>
    <dc:creator>Hello_there</dc:creator>
    <dc:date>2023-01-12T14:27:27Z</dc:date>
    <item>
      <title>How do i create a series of macro variables using an array and do loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-create-a-series-of-macro-variables-using-an-array-and/m-p/853449#M337324</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is a data manipulation exercise. I'm trying to use the following data to macrotize the values in 4 out of the 5 variables. I'm new to the arrays, but i'm not sure what i'm doing wrong.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the data:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have; 
infile datalines dsd dlm=",";
	input word1 $ word2 $ word3$ word4$ word5$;
datalines;
We, are, here, now., pretzel
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;My code doesn't work. I want to only macrotize the the values from word1 to word4. Thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_; set have;

array word[4] word1--word4;
do i=1 to 4;

	call symput('word[i]', word[i]);
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The desired outcome:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to create 4 macro variables that are named the following, "word1", "word2", "word3", "word4", using only the variables word1, word2, word3, word4&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jan 2023 14:27:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-create-a-series-of-macro-variables-using-an-array-and/m-p/853449#M337324</guid>
      <dc:creator>Hello_there</dc:creator>
      <dc:date>2023-01-12T14:27:27Z</dc:date>
    </item>
    <item>
      <title>Re: How do i create a series of macro variables using an array and do loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-create-a-series-of-macro-variables-using-an-array-and/m-p/853451#M337325</link>
      <description>&lt;P&gt;The first argument of call symput ought to be a text string containing the name of the macro variable you want to create.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;call symput('word[i]', word[i]);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;creates macro variables with the name of text string in the first argument to call symput, so you are creating macro variables with the (illegal) name of word[i] and so macro variables cannot be created. Instead, you need to make the first argument of call symput a valid text string, such as word1 word2 &lt;EM&gt;etc&lt;/EM&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;call symput(cats('word',i), word[i]);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The first argument, when the loop variable I is equal to 1, &lt;FONT face="courier new,courier"&gt;cats('word',i)&lt;/FONT&gt; equals&amp;nbsp;&lt;FONT face="courier new,courier"&gt;word1&lt;/FONT&gt;&amp;nbsp;so a macro variable named WORD1 is created with the value of word[1]&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jan 2023 15:02:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-create-a-series-of-macro-variables-using-an-array-and/m-p/853451#M337325</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-01-12T15:02:10Z</dc:date>
    </item>
    <item>
      <title>Re: How do i create a series of macro variables using an array and do loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-create-a-series-of-macro-variables-using-an-array-and/m-p/853453#M337326</link>
      <description>Thanks!</description>
      <pubDate>Thu, 12 Jan 2023 14:49:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-create-a-series-of-macro-variables-using-an-array-and/m-p/853453#M337326</guid>
      <dc:creator>Hello_there</dc:creator>
      <dc:date>2023-01-12T14:49:16Z</dc:date>
    </item>
    <item>
      <title>Re: How do i create a series of macro variables using an array and do loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-create-a-series-of-macro-variables-using-an-array-and/m-p/853459#M337327</link>
      <description>&lt;P&gt;First thing is that unless you really have a pressing need to insert leading and/or trailing spaces into the macro variables you should not be using ancient CALL SYMPUT() routine.&amp;nbsp; Use CAL SYMPUTX() instead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use CATS() to append the integer to the macro variable name.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;call symputx(cats('word',i), word[i]);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Jan 2023 14:51:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-create-a-series-of-macro-variables-using-an-array-and/m-p/853459#M337327</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-01-12T14:51:07Z</dc:date>
    </item>
    <item>
      <title>Re: How do i create a series of macro variables using an array and do loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-create-a-series-of-macro-variables-using-an-array-and/m-p/853463#M337328</link>
      <description>I actually do in my case need to have leading and trailing space. I know it's rare.</description>
      <pubDate>Thu, 12 Jan 2023 14:52:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-create-a-series-of-macro-variables-using-an-array-and/m-p/853463#M337328</guid>
      <dc:creator>Hello_there</dc:creator>
      <dc:date>2023-01-12T14:52:52Z</dc:date>
    </item>
  </channel>
</rss>

