<?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 Can I Generate MACRO VARIABLE That Includes Same Text Strings Repeatedly, and with Name I Wa in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-Can-I-Generate-MACRO-VARIABLE-That-Includes-Same-Text/m-p/597192#M172059</link>
    <description>&lt;P&gt;I usually prefer to build my macro variables in data steps, as the syntax is simpler, and I do not need %sysfunc to use data step functions.&lt;/P&gt;
&lt;P&gt;But here there are two factors:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;concatenating is extremely easy in macro language, as you can see&lt;/LI&gt;
&lt;LI&gt;by only using macro code, this macro can be placed right in the middle of a data or procedure step, without causing a step boundary&lt;/LI&gt;
&lt;/UL&gt;</description>
    <pubDate>Thu, 17 Oct 2019 06:33:27 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2019-10-17T06:33:27Z</dc:date>
    <item>
      <title>How Can I Generate MACRO VARIABLE That Includes Same Text Strings Repeatedly, and with Name I Want?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-Can-I-Generate-MACRO-VARIABLE-That-Includes-Same-Text/m-p/597169#M172042</link>
      <description>&lt;P&gt;Hello, there:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to generate macro variable that includes same strings repeatedly, and that has name I want.&lt;/P&gt;&lt;P&gt;I have 3 ideas (for more details, please see below), and like Pattern 3, I would like to generate macro variable with name I want in same step (in MACRO setting).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But after submitting Pattern 3 code, I get WARNING. I do not know why and how to resolve this problem.&lt;/P&gt;&lt;P&gt;If you have any ideas, please let me know. Any ideas would be welcome.&lt;/P&gt;&lt;P&gt;Thank you in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;***** Pattern 1 ;&lt;/P&gt;&lt;P&gt;In this pattern, I have to define null macro variable first.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* Pattern 1: Define MACRO VARIABLEs in advance ;
***** First, you have to define MACRO VARIABLEs you want ;
%let re5=;

***** Second, specify word you want to repeat ;
%let t=WORD;

***** MACRO Setting ;
%macro re(max=);
data re(drop=i);
    length re $2000.;
    array ar1(*) $ re1-re&amp;amp;max.;
    do i=1 to dim(ar1);
        ar1(i)='&amp;amp;t';
    end;
    re=catx(" ", of re1-re&amp;amp;max.);
run;
proc sql noprint;
    select re into :re&amp;amp;max.
    from work.re
    ;
quit;
%mend re;

***** Finally, generate MACRO VARIABLE &amp;amp; check content ;
%re(max=5)
%put &amp;amp;re5.;
***** If you don't define MACRO VARIABLEs in advance, get WARNING ;
%re(max=100)
%put &amp;amp;re100.;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;***** Pattern 2 ;&lt;/P&gt;&lt;P&gt;In this pattern, after submitting MACRO, I have to define macro variable with name I want.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* Pattern 2: After setting MACRO, Store MACRO VARIABLEs with name you want ;
***** First, specify word you want to repeat ;
%let t=WORD;

***** MACRO Setting ;
%macro re(max=);
data re(drop=i);
    length re $2000.;
    array ar1(*) $ re1-re&amp;amp;max.;
    do i=1 to dim(ar1);
        ar1(i)='&amp;amp;t';
    end;
    re=catx(" ", of re1-re&amp;amp;max.);
run;
%mend re;

***** Second, submit your MACRO ;
%re(max=10)

***** Finally, generate MACRO VARIABLE with name you want &amp;amp; check ;
proc sql noprint;
    select re into :re10
    from work.re
    ;
quit;
%put &amp;amp;re10.;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;***** Pattern 3 ;&lt;/P&gt;&lt;P&gt;In this pattern, I think I can generate macro variable with name I want, but this code does not work.....&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* Pattern 3: In same step (MACRO Setting), generate MACRO VARIABLE with name you want ;
***** NOTE: There're some problems in this method ;
***** First, specify word you want to repeat ;
%let t=WORD;

***** MACRO Setting ;
%macro re(max=);
data re(drop=i);
    length re $2000.;
    array ar1(*) $ re1-re&amp;amp;max.;
    do i=1 to dim(ar1);
        ar1(i)='&amp;amp;t';
    end;
    re=catx(" ", of re1-re&amp;amp;max.);
run;
********** At here, in MACRO Setting, I want to generate MACRO VARIABLE with name I want, but something is wrong..... ;
data _null_;
    set re;
    call symputx("re&amp;amp;max.", re);
run;
%mend re;

***** Finally, generate MACRO VARIABLE &amp;amp; check content ;
%re(max=15)
%put &amp;amp;re15.; * &amp;lt;----------Submit WARNING ?????????? ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Oct 2019 04:49:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-Can-I-Generate-MACRO-VARIABLE-That-Includes-Same-Text/m-p/597169#M172042</guid>
      <dc:creator>KentaMURANAKA</dc:creator>
      <dc:date>2019-10-17T04:49:39Z</dc:date>
    </item>
    <item>
      <title>Re: How Can I Generate MACRO VARIABLE That Includes Same Text Strings Repeatedly, and with Name I Wa</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-Can-I-Generate-MACRO-VARIABLE-That-Includes-Same-Text/m-p/597173#M172046</link>
      <description>&lt;P&gt;Try next code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let txt=any string # ;
%let n =3;

data _NULL_;
  length long_string = repeat("&amp;amp;txt", &amp;amp;n-1);
  call symput('Check', strip(long_string));
run;

%put &amp;amp;check;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Oct 2019 05:07:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-Can-I-Generate-MACRO-VARIABLE-That-Includes-Same-Text/m-p/597173#M172046</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2019-10-17T05:07:50Z</dc:date>
    </item>
    <item>
      <title>Re: How Can I Generate MACRO VARIABLE That Includes Same Text Strings Repeatedly, and with Name I Wa</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-Can-I-Generate-MACRO-VARIABLE-That-Includes-Same-Text/m-p/597178#M172049</link>
      <description>&lt;P&gt;Hi, Shmuel-san:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for quick reply &amp;amp; your code is simple, wonderful.&lt;/P&gt;&lt;P&gt;I did not know REPEAT function.&lt;/P&gt;&lt;P&gt;Below works.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let txt=%str(WORD );
%let max=5;
data _null_;
    length re $2000.;
    re=repeat("&amp;amp;txt", &amp;amp;max.-1);
    call symputx("re&amp;amp;max.", strip(re));
run;
%put &amp;amp;&amp;amp;re&amp;amp;max..;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But I want to use multiple macro variables like RE5 (5 times repeated), or RE10 (10 times repeated), etc., so if possible, I want to conduct this operation in MACRO. Referring to your code, I tried to create this MACRO, but I get WARNING.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let txt=%str(WORD );
%macro re(max=);
data _null_;
    length re $2000.;
    re=repeat("&amp;amp;txt", &amp;amp;max.-1);
    call symputx("re&amp;amp;max.", strip(re));
run;
%mend re;
%re(max=10)
%put &amp;amp;re10.;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Do you know why and how to resolve this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Oct 2019 05:41:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-Can-I-Generate-MACRO-VARIABLE-That-Includes-Same-Text/m-p/597178#M172049</guid>
      <dc:creator>KentaMURANAKA</dc:creator>
      <dc:date>2019-10-17T05:41:20Z</dc:date>
    </item>
    <item>
      <title>Re: How Can I Generate MACRO VARIABLE That Includes Same Text Strings Repeatedly, and with Name I Wa</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-Can-I-Generate-MACRO-VARIABLE-That-Includes-Same-Text/m-p/597179#M172050</link>
      <description>&lt;P&gt;You can do it in the macro without using an additional data step, and it's not even complicated:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro repeat_text(varname,text,rep);
%global &amp;amp;varname.;
%let &amp;amp;varname.=;
%do i = 1 %to &amp;amp;rep.;
  %let &amp;amp;varname=&amp;amp;&amp;amp;&amp;amp;varname. &amp;amp;text.;
%end;
%mend;

%repeat_text(re,word,3)

%put &amp;amp;re.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Log:&lt;/P&gt;
&lt;PRE&gt;37         %macro repeat_text(varname,text,rep);
38         %global &amp;amp;varname.;
39         %let &amp;amp;varname.=;
40         %do i = 1 %to &amp;amp;rep.;
41           %let &amp;amp;varname=&amp;amp;&amp;amp;&amp;amp;varname. &amp;amp;text.;
42         %end;
43         %mend;
44         
45         %repeat_text(re,word,3)
46         
47         %put &amp;amp;re.;
word word word
&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Oct 2019 05:43:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-Can-I-Generate-MACRO-VARIABLE-That-Includes-Same-Text/m-p/597179#M172050</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-10-17T05:43:21Z</dc:date>
    </item>
    <item>
      <title>Re: How Can I Generate MACRO VARIABLE That Includes Same Text Strings Repeatedly, and with Name I Wa</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-Can-I-Generate-MACRO-VARIABLE-That-Includes-Same-Text/m-p/597185#M172054</link>
      <description>&lt;P&gt;In your code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let txt=%str(WORD );
%macro re(max=);
data _null_;
    length re $2000.;
    re=repeat("&amp;amp;txt", &amp;amp;max.-1);
    call symputx("re&amp;amp;max.", strip(re));
run;
%mend re;
%re(max=10)
%put &amp;amp;re10.;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;the RE&amp;amp;max macro variable is created inside the macro code, which means it is by default local macro variable.&lt;/P&gt;
&lt;P&gt;You need to add &lt;STRONG&gt;%global re&amp;amp;max;&lt;/STRONG&gt; statement inside the macro.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Oct 2019 06:02:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-Can-I-Generate-MACRO-VARIABLE-That-Includes-Same-Text/m-p/597185#M172054</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2019-10-17T06:02:11Z</dc:date>
    </item>
    <item>
      <title>Re: How Can I Generate MACRO VARIABLE That Includes Same Text Strings Repeatedly, and with Name I Wa</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-Can-I-Generate-MACRO-VARIABLE-That-Includes-Same-Text/m-p/597186#M172055</link>
      <description>&lt;P&gt;Hi, KurtBremser-san:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for reply. Your code worked! Aha!&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro re(var=, txt=, rep=);
%global &amp;amp;var.;
%let &amp;amp;var.=;
%do i=1 %to &amp;amp;rep.;
%let &amp;amp;var.=&amp;amp;&amp;amp;&amp;amp;var. &amp;amp;txt.;
%end;
%mend re;

%re(var=re10, txt=WORD, rep=10)
%put &amp;amp;re10.;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;I think three ampersands are important (I do not understand why).&lt;/P&gt;&lt;P&gt;Anyway, thank you, KurtBremser-san, Shmuel-san!!&lt;/P&gt;</description>
      <pubDate>Thu, 17 Oct 2019 06:05:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-Can-I-Generate-MACRO-VARIABLE-That-Includes-Same-Text/m-p/597186#M172055</guid>
      <dc:creator>KentaMURANAKA</dc:creator>
      <dc:date>2019-10-17T06:05:14Z</dc:date>
    </item>
    <item>
      <title>Re: How Can I Generate MACRO VARIABLE That Includes Same Text Strings Repeatedly, and with Name I Wa</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-Can-I-Generate-MACRO-VARIABLE-That-Includes-Same-Text/m-p/597188#M172056</link>
      <description>&lt;P&gt;Regarding the three ampersands:&lt;/P&gt;
&lt;P&gt;When the macro processor resolves macro triggers (&amp;amp; or %), it can and will do so repeatedly.&lt;/P&gt;
&lt;P&gt;Two ampersands are converted to one on each pass, so what happens is this:&lt;/P&gt;
&lt;P&gt;Pass 1:&lt;/P&gt;
&lt;PRE&gt;&amp;amp;&amp;amp;&amp;amp;varname. -&amp;gt; &amp;amp; (converted from the first two ampersands) re10 (content of macro variable &amp;amp;varname)&lt;/PRE&gt;
&lt;P&gt;so you get&lt;/P&gt;
&lt;PRE&gt;&amp;amp;re10&lt;/PRE&gt;
&lt;P&gt;(the dot is removed; if this was part of some longer string, you also need to add additional dots for each pass)&lt;/P&gt;
&lt;P&gt;Pass 2:&lt;/P&gt;
&lt;PRE&gt;&amp;amp;re10. --&amp;gt; (contents of &amp;amp;re10)&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Oct 2019 06:11:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-Can-I-Generate-MACRO-VARIABLE-That-Includes-Same-Text/m-p/597188#M172056</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-10-17T06:11:21Z</dc:date>
    </item>
    <item>
      <title>Re: How Can I Generate MACRO VARIABLE That Includes Same Text Strings Repeatedly, and with Name I Wa</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-Can-I-Generate-MACRO-VARIABLE-That-Includes-Same-Text/m-p/597190#M172057</link>
      <description>&lt;P&gt;Hi, KurtBremser-san:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your kind advice. I understand now!&lt;/P&gt;&lt;P&gt;Regarding to "%let &amp;amp;var.=&amp;amp;&amp;amp;&amp;amp;var.. &amp;amp;txt.",&lt;/P&gt;&lt;P&gt;first "&amp;amp;var." means variable name,&lt;/P&gt;&lt;P&gt;and second "&amp;amp;&amp;amp;&amp;amp;var.." means, not variable name, it means variable content.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!!&lt;/P&gt;</description>
      <pubDate>Thu, 17 Oct 2019 06:22:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-Can-I-Generate-MACRO-VARIABLE-That-Includes-Same-Text/m-p/597190#M172057</guid>
      <dc:creator>KentaMURANAKA</dc:creator>
      <dc:date>2019-10-17T06:22:50Z</dc:date>
    </item>
    <item>
      <title>Re: How Can I Generate MACRO VARIABLE That Includes Same Text Strings Repeatedly, and with Name I Wa</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-Can-I-Generate-MACRO-VARIABLE-That-Includes-Same-Text/m-p/597191#M172058</link>
      <description>&lt;P&gt;Hi, Shmuel-san:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you, I understand!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In summary,&amp;nbsp;&lt;/P&gt;&lt;P&gt;KurtBremser-san's idea is.....&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro re(var=, txt=, rep=);
%global &amp;amp;var.;
%let &amp;amp;var.=;
%do i=1 %to &amp;amp;rep.;
%let &amp;amp;var.=&amp;amp;&amp;amp;&amp;amp;var. &amp;amp;txt.;
%end;
%mend re;

%re(var=re10, txt=WORD, rep=10)
%put &amp;amp;re10.;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;and Shmuel-san's idea is.....&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let txt=%str(WORD );
%macro re(max=);
%global re&amp;amp;max.;
data _null_;
    length re $2000.;
    re=repeat("&amp;amp;txt", &amp;amp;max.-1);
    call symputx("re&amp;amp;max.", strip(re));
run;
%mend re;
%re(max=7)
%put &amp;amp;re7.;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I think both ideas are wonderful.&lt;/P&gt;&lt;P&gt;Thank you, Shmuel-san, KurtBremser-san!!&lt;/P&gt;</description>
      <pubDate>Thu, 17 Oct 2019 06:30:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-Can-I-Generate-MACRO-VARIABLE-That-Includes-Same-Text/m-p/597191#M172058</guid>
      <dc:creator>KentaMURANAKA</dc:creator>
      <dc:date>2019-10-17T06:30:03Z</dc:date>
    </item>
    <item>
      <title>Re: How Can I Generate MACRO VARIABLE That Includes Same Text Strings Repeatedly, and with Name I Wa</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-Can-I-Generate-MACRO-VARIABLE-That-Includes-Same-Text/m-p/597192#M172059</link>
      <description>&lt;P&gt;I usually prefer to build my macro variables in data steps, as the syntax is simpler, and I do not need %sysfunc to use data step functions.&lt;/P&gt;
&lt;P&gt;But here there are two factors:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;concatenating is extremely easy in macro language, as you can see&lt;/LI&gt;
&lt;LI&gt;by only using macro code, this macro can be placed right in the middle of a data or procedure step, without causing a step boundary&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Thu, 17 Oct 2019 06:33:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-Can-I-Generate-MACRO-VARIABLE-That-Includes-Same-Text/m-p/597192#M172059</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-10-17T06:33:27Z</dc:date>
    </item>
    <item>
      <title>Re: How Can I Generate MACRO VARIABLE That Includes Same Text Strings Repeatedly, and with Name I Wa</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-Can-I-Generate-MACRO-VARIABLE-That-Includes-Same-Text/m-p/597193#M172060</link>
      <description>&lt;P&gt;Hi, KurtBremser-san:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think same as you.&lt;/P&gt;&lt;P&gt;I almost always create macro variables in DATA step (or SQL step),&lt;/P&gt;&lt;P&gt;so for me, your idea is eye-opener.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you !&lt;/P&gt;</description>
      <pubDate>Thu, 17 Oct 2019 06:43:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-Can-I-Generate-MACRO-VARIABLE-That-Includes-Same-Text/m-p/597193#M172060</guid>
      <dc:creator>KentaMURANAKA</dc:creator>
      <dc:date>2019-10-17T06:43:36Z</dc:date>
    </item>
  </channel>
</rss>

