<?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 Editing macro list in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Editing-macro-list/m-p/411529#M26435</link>
    <description>&lt;P&gt;Hi,&lt;BR /&gt;I am wondering how to edit macro list to add suffix to all of its items.&lt;BR /&gt;&lt;BR /&gt;Let's say I have&lt;/P&gt;&lt;PRE&gt;%let vars=one_ two_ three_;&lt;/PRE&gt;&lt;P&gt;I would like to make a macro that loops several times (10x) and in each loop it adds different suffix to &amp;amp;vars.&lt;BR /&gt;&lt;BR /&gt;I came accross SAS list string utils from Jiangtang Hu - &lt;A href="https://encrypted.google.com/url?sa=t&amp;amp;rct=j&amp;amp;q=&amp;amp;esrc=s&amp;amp;source=web&amp;amp;cd=1&amp;amp;ved=0ahUKEwjIsuTvl6_XAhVDrRoKHQuaB1AQFggmMAA&amp;amp;url=http%3A%2F%2Fanalytics.ncsu.edu%2Fsesug%2F2013%2FBtB-18.pdf&amp;amp;usg=AOvVaw2r3lI-y4vyBtkz12ecAlLm" target="_self"&gt;List Processing with SAS: A Comprehensive Survey&lt;/A&gt;&lt;/P&gt;&lt;P&gt;and I used edited version of his %add_string macro:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;%macro add_string(words, str, delim=%str( ), location=suffix); 
    %local outstr i word num_words;
 
    * Build the outstr by looping through the words list and adding the 
    * requested string onto each word. ; 
    %let outstr = ; 
    %let num_words = %sysfunc(countw(&amp;amp;words)); 
    %do i=1 %to &amp;amp;num_words; 
        %let word = %scan(&amp;amp;words, &amp;amp;i, &amp;amp;delim); 
        %if (&amp;amp;i eq 1) %then %do; 
            %if (%upcase(&amp;amp;location) eq PREFIX) %then %do; 
                %let outstr = &amp;amp;str&amp;amp;word; 
            %end; 
            %else %do; 
                %let outstr = &amp;amp;word&amp;amp;str; 
            %end; 
        %end; 
        %else %do; 
            %if (%upcase(&amp;amp;location) eq PREFIX) %then %do; 
                %let outstr = &amp;amp;outstr&amp;amp;delim&amp;amp;str&amp;amp;word; 
            %end; 
            %else %do; 
                %let outstr = &amp;amp;outstr&amp;amp;delim&amp;amp;word&amp;amp;str; 
            %end; 
        %end; 
    %end; 
    * Output the new list of words. ; 
    &amp;amp;outstr 
%mend add_string;&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;The problem is how to handle the output from such a macro? When I call it I get an Error : Statement is no valid:&lt;/P&gt;&lt;PRE&gt;%let vars=one_ two_ three_;
%let vars1r=%add_string(&amp;amp;vars, 1r);&lt;BR /&gt;"ERROR 180-322: STATEMENT IS NOT VALID OR IT IS USED OUT OF PROPER ORDER."&lt;/PRE&gt;&lt;P&gt;the problem is causing&lt;/P&gt;&lt;PRE&gt;&amp;amp;outstr&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;in macro definition, but I don't know how to output from macro in other way. (I am working with SAS enterprise guide 9.4)&lt;BR /&gt;&lt;BR /&gt;Any suggestions? Thanks...&lt;/P&gt;</description>
    <pubDate>Wed, 08 Nov 2017 14:38:28 GMT</pubDate>
    <dc:creator>Maty</dc:creator>
    <dc:date>2017-11-08T14:38:28Z</dc:date>
    <item>
      <title>Editing macro list</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Editing-macro-list/m-p/411529#M26435</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;I am wondering how to edit macro list to add suffix to all of its items.&lt;BR /&gt;&lt;BR /&gt;Let's say I have&lt;/P&gt;&lt;PRE&gt;%let vars=one_ two_ three_;&lt;/PRE&gt;&lt;P&gt;I would like to make a macro that loops several times (10x) and in each loop it adds different suffix to &amp;amp;vars.&lt;BR /&gt;&lt;BR /&gt;I came accross SAS list string utils from Jiangtang Hu - &lt;A href="https://encrypted.google.com/url?sa=t&amp;amp;rct=j&amp;amp;q=&amp;amp;esrc=s&amp;amp;source=web&amp;amp;cd=1&amp;amp;ved=0ahUKEwjIsuTvl6_XAhVDrRoKHQuaB1AQFggmMAA&amp;amp;url=http%3A%2F%2Fanalytics.ncsu.edu%2Fsesug%2F2013%2FBtB-18.pdf&amp;amp;usg=AOvVaw2r3lI-y4vyBtkz12ecAlLm" target="_self"&gt;List Processing with SAS: A Comprehensive Survey&lt;/A&gt;&lt;/P&gt;&lt;P&gt;and I used edited version of his %add_string macro:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;%macro add_string(words, str, delim=%str( ), location=suffix); 
    %local outstr i word num_words;
 
    * Build the outstr by looping through the words list and adding the 
    * requested string onto each word. ; 
    %let outstr = ; 
    %let num_words = %sysfunc(countw(&amp;amp;words)); 
    %do i=1 %to &amp;amp;num_words; 
        %let word = %scan(&amp;amp;words, &amp;amp;i, &amp;amp;delim); 
        %if (&amp;amp;i eq 1) %then %do; 
            %if (%upcase(&amp;amp;location) eq PREFIX) %then %do; 
                %let outstr = &amp;amp;str&amp;amp;word; 
            %end; 
            %else %do; 
                %let outstr = &amp;amp;word&amp;amp;str; 
            %end; 
        %end; 
        %else %do; 
            %if (%upcase(&amp;amp;location) eq PREFIX) %then %do; 
                %let outstr = &amp;amp;outstr&amp;amp;delim&amp;amp;str&amp;amp;word; 
            %end; 
            %else %do; 
                %let outstr = &amp;amp;outstr&amp;amp;delim&amp;amp;word&amp;amp;str; 
            %end; 
        %end; 
    %end; 
    * Output the new list of words. ; 
    &amp;amp;outstr 
%mend add_string;&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;The problem is how to handle the output from such a macro? When I call it I get an Error : Statement is no valid:&lt;/P&gt;&lt;PRE&gt;%let vars=one_ two_ three_;
%let vars1r=%add_string(&amp;amp;vars, 1r);&lt;BR /&gt;"ERROR 180-322: STATEMENT IS NOT VALID OR IT IS USED OUT OF PROPER ORDER."&lt;/PRE&gt;&lt;P&gt;the problem is causing&lt;/P&gt;&lt;PRE&gt;&amp;amp;outstr&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;in macro definition, but I don't know how to output from macro in other way. (I am working with SAS enterprise guide 9.4)&lt;BR /&gt;&lt;BR /&gt;Any suggestions? Thanks...&lt;/P&gt;</description>
      <pubDate>Wed, 08 Nov 2017 14:38:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Editing-macro-list/m-p/411529#M26435</guid>
      <dc:creator>Maty</dc:creator>
      <dc:date>2017-11-08T14:38:28Z</dc:date>
    </item>
    <item>
      <title>Re: Editing macro list</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Editing-macro-list/m-p/411532#M26436</link>
      <description>&lt;P&gt;Use Base SAS - this is the underlying code which is executed, macro only creates this Base SAS code.&amp;nbsp; It is used for all data processing.&amp;nbsp; Also, without knowing anything about your process its hard to say so this is just guessing.&amp;nbsp; Say I want to create a dataset for each word in the given list, with a second suffix:&lt;/P&gt;
&lt;PRE&gt;%let vars=one_ two_ three_;

%macro Create_DS (in_name=,suff=);
  data &amp;amp;in_name.&amp;amp;suff.;
    set sashelp.class;
  run;
%mend Create_DS;

data _null_;
  do curr_suffix="abc","def","ghi";
    do i=1 to countw("&amp;amp;vars."," ");
      call execute(cats('%Create_DS (in_name=',scan(&amp;amp;vars.,i,' '),',suff=',curr_suffix,');'));
    end;
  end;
run;&lt;/PRE&gt;
&lt;P&gt;Basically this will create a macro call for each word in the macro variable, and each suffix in the do loop, so you would end up with:&lt;BR /&gt;one_abc&lt;/P&gt;
&lt;P&gt;one_def&lt;/P&gt;
&lt;P&gt;one_ghi&lt;/P&gt;
&lt;P&gt;two_abc&lt;/P&gt;
&lt;P&gt;two_def&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;</description>
      <pubDate>Wed, 08 Nov 2017 14:46:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Editing-macro-list/m-p/411532#M26436</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-11-08T14:46:39Z</dc:date>
    </item>
    <item>
      <title>Re: Editing macro list</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Editing-macro-list/m-p/411534#M26437</link>
      <description>&lt;P&gt;Nice problem!&amp;nbsp; Try changing all&amp;nbsp;the comment statements to macro comment statements, such as:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%* Output the new list of words;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As it stands now, the comment statements become generated text, part of the value being assigned to VARS1R.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Nov 2017 14:56:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Editing-macro-list/m-p/411534#M26437</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-11-08T14:56:40Z</dc:date>
    </item>
    <item>
      <title>Re: Editing macro list</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Editing-macro-list/m-p/411535#M26438</link>
      <description>&lt;P&gt;Thanks! That did the trick ...&lt;/P&gt;</description>
      <pubDate>Wed, 08 Nov 2017 15:00:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Editing-macro-list/m-p/411535#M26438</guid>
      <dc:creator>Maty</dc:creator>
      <dc:date>2017-11-08T15:00:22Z</dc:date>
    </item>
  </channel>
</rss>

