<?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: Iteratively list big set of macro var for a proc in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Iteratively-list-big-set-of-macro-var-for-a-proc/m-p/835627#M330350</link>
    <description>&lt;P&gt;Oh boy, what a miss. Clearly the semi-colon within the macro iterations would be repeated too, and close multiple times the var statement in the proc rank. It's a never ending learning path...Thanks Paige&lt;/P&gt;</description>
    <pubDate>Wed, 28 Sep 2022 14:48:46 GMT</pubDate>
    <dc:creator>dcortell</dc:creator>
    <dc:date>2022-09-28T14:48:46Z</dc:date>
    <item>
      <title>Iteratively list big set of macro var for a proc</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Iteratively-list-big-set-of-macro-var-for-a-proc/m-p/835609#M330340</link>
      <description>&lt;P&gt;Hi all&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to perform a proc rank on a large set of macro vars. Code below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;%macro assign;
%do ii=1 %to &amp;amp;max_grams;

%global bigrams&amp;amp;ii 
rank_bigrams&amp;amp;ii;

proc sql noprint;
select

cat('"',trim(_term_),'"n'),

cat('"rank_',trim(_term_),'"n') 


into :bigrams&amp;amp;ii ,
:rank_bigrams&amp;amp;ii

from test
where count=&amp;amp;ii;
quit;


%end;
%mend;

%assign;

%macro putt_big;
%do ii=1 %to &amp;amp;max_grams;
&amp;amp;&amp;amp;bigrams&amp;amp;ii;  
%end;
%mend;


%macro putt_rank;
%do ii=1 %to &amp;amp;max_grams;
&amp;amp;&amp;amp;rank_bigrams&amp;amp;ii; 
%end;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;proc transpose data=test out=test_tr&lt;BR /&gt;(drop=_name_ _label_) ;&lt;BR /&gt;id _term_;&lt;BR /&gt;var N;&lt;BR /&gt;run;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc rank data=test_tr groups=10 out=test2; var %putt_big ; ranks %putt_rank; run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE class=""&gt;MLOGIC(PUTT_BIG):  %DO loop index variable II is now 101; loop will not iterate again.
MPRINT(PUTT_BIG):   "__a"n "__b"n "__c"n "__d"n "__e"n "__f"n "__g"n "__h"n "__i"n "__j"n "__k"n "__l"n "__m"n "__n"n "__o"n "__p"n 
"__q"n "__r"n "__s"n "__t"n "__u"n "__v"n "__w"n "__x"n "__y"n "__z"n "_a_"n "_aa"n "_ab"n "_ac"n "_ad"n "_ae"n "_af"n "_ag"n 
"_ah"n "_ai"n "_aj"n "_ak"n "_al"n "_am"n "_an"n "_ao"n "_ap"n "_aq"n "_ar"n "_as"n "_at"n "_au"n "_av"n "_aw"n "_ax"n "_ay"n 
"_az"n "_b_"n "_ba"n "_bb"n "_bc"n "_bd"n "_be"n "_bh"n "_bi"n "_bj"n "_bk"n "_bl"n "_bm"n "_bn"n "_bo"n "_bp"n "_br"n "_bs"n 
"_bt"n "_bu"n "_bv"n "_by"n "_bz"n "_c_"n "_ca"n "_cb"n "_cc"n "_cd"n "_ce"n "_cf"n "_cg"n "_ch"n "_ci"n "_ck"n "_cl"n "_cm"n 
"_cn"n "_co"n "_cp"n "_cr"n "_cs"n "_ct"n "_cu"n "_cv"n "_cy"n "_cz"n "_d_"n
MLOGIC(PUTT_BIG):  Ending execution.
ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;However, I'm getting the error above when the macros are called within proc rank:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Pretty sure is something about how the macro are resolved within the macros&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any idea about where to look?&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;</description>
      <pubDate>Wed, 28 Sep 2022 14:27:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Iteratively-list-big-set-of-macro-var-for-a-proc/m-p/835609#M330340</guid>
      <dc:creator>dcortell</dc:creator>
      <dc:date>2022-09-28T14:27:22Z</dc:date>
    </item>
    <item>
      <title>Re: Iteratively list big set of macro var for a proc</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Iteratively-list-big-set-of-macro-var-for-a-proc/m-p/835613#M330342</link>
      <description>&lt;P&gt;Please show us the &lt;FONT color="#FF0000"&gt;ENTIRE&lt;/FONT&gt; log for this PROC RANK. (and in the future, we also need entire log for a given PROC or DATA step, not parts of it)&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Have you considered using more meaningful — and easier to type — variable names?&lt;/P&gt;</description>
      <pubDate>Wed, 28 Sep 2022 14:14:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Iteratively-list-big-set-of-macro-var-for-a-proc/m-p/835613#M330342</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-09-28T14:14:46Z</dc:date>
    </item>
    <item>
      <title>Re: Iteratively list big set of macro var for a proc</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Iteratively-list-big-set-of-macro-var-for-a-proc/m-p/835620#M330346</link>
      <description>&lt;P&gt;The macros iterate for 100 times, so I will just add the initial log of the proc rank, as the iterations are all the same for the 100 macro vars:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;83    proc rank data=test_tr groups=10 out=test2;
84    var %putt_big ;
MLOGIC(PUTT_BIG):  Beginning execution.
SYMBOLGEN:  Macro variable MAX_GRAMS resolves to      100
MLOGIC(PUTT_BIG):  %DO loop beginning; index variable II; start value is 1; stop value is 100; by value is 1.  
SYMBOLGEN:  &amp;amp;&amp;amp; resolves to &amp;amp;.
SYMBOLGEN:  Macro variable II resolves to 1
SYMBOLGEN:  Macro variable BIGRAMS1 resolves to "___"n                                                                              
                                                                                                                                
MPRINT(PUTT_BIG):   "___"n ;
MLOGIC(PUTT_BIG):  %DO loop index variable II is now 2; loop will iterate again.
SYMBOLGEN:  &amp;amp;&amp;amp; resolves to &amp;amp;.
SYMBOLGEN:  Macro variable II resolves to 2
SYMBOLGEN:  Macro variable BIGRAMS2 resolves to "__a"n                                                                              
                                                                                                                                
NOTE: Line generated by the macro variable "BIGRAMS2".
84     "__a"n
       ------
       180
MLOGIC(PUTT_BIG):  %DO loop index variable II is now 3; loop will iterate again.
SYMBOLGEN:  &amp;amp;&amp;amp; resolves to &amp;amp;.
SYMBOLGEN:  Macro variable II resolves to 3
SYMBOLGEN:  Macro variable BIGRAMS3 resolves to "__b"n                                                                              
                                                                                                                                
NOTE: Line generated by the macro variable "BIGRAMS3".
84     "__b"n
       ------
       180&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The ending part of the log is as the one posted above, where the error happens:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;MLOGIC(PUTT_BIG):  %DO loop index variable II is now 100; loop will iterate again.
SYMBOLGEN:  &amp;amp;&amp;amp; resolves to &amp;amp;.
SYMBOLGEN:  Macro variable II resolves to 100
SYMBOLGEN:  Macro variable BIGRAMS100 resolves to "_d_"n                                                                            
                                                                                                                                  
NOTE: Line generated by the macro variable "BIGRAMS100".
84     "_d_"n
       ------
       180
MLOGIC(PUTT_BIG):  %DO loop index variable II is now 101; loop will not iterate again.
MPRINT(PUTT_BIG):   "__a"n "__b"n "__c"n "__d"n "__e"n "__f"n "__g"n "__h"n "__i"n "__j"n "__k"n "__l"n "__m"n "__n"n "__o"n "__p"n 
"__q"n "__r"n "__s"n "__t"n "__u"n "__v"n "__w"n "__x"n "__y"n "__z"n "_a_"n "_aa"n "_ab"n "_ac"n "_ad"n "_ae"n "_af"n "_ag"n 
"_ah"n "_ai"n "_aj"n "_ak"n "_al"n "_am"n "_an"n "_ao"n "_ap"n "_aq"n "_ar"n "_as"n "_at"n "_au"n "_av"n "_aw"n "_ax"n "_ay"n 
"_az"n "_b_"n "_ba"n "_bb"n "_bc"n "_bd"n "_be"n "_bh"n "_bi"n "_bj"n "_bk"n "_bl"n "_bm"n "_bn"n "_bo"n "_bp"n "_br"n "_bs"n 
"_bt"n "_bu"n "_bv"n "_by"n "_bz"n "_c_"n "_ca"n "_cb"n "_cc"n "_cd"n "_ce"n "_cf"n "_cg"n "_ch"n "_ci"n "_ck"n "_cl"n "_cm"n 
"_cn"n "_co"n "_cp"n "_cr"n "_cs"n "_ct"n "_cu"n "_cv"n "_cy"n "_cz"n "_d_"n
MLOGIC(PUTT_BIG):  Ending execution.
ERROR 180-322: Statement is not valid or it is used out of proper order.
85    ranks %putt_rank;
MLOGIC(PUTT_RANK):  Beginning execution.&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Sep 2022 14:29:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Iteratively-list-big-set-of-macro-var-for-a-proc/m-p/835620#M330346</guid>
      <dc:creator>dcortell</dc:creator>
      <dc:date>2022-09-28T14:29:51Z</dc:date>
    </item>
    <item>
      <title>Re: Iteratively list big set of macro var for a proc</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Iteratively-list-big-set-of-macro-var-for-a-proc/m-p/835623#M330347</link>
      <description>&lt;P&gt;I think this is nightmare code and nightmare variable names, and I would urge you to consider simplification and using meaningful variable names. Nevertheless, I think your error is here:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro putt_rank;
%do ii=1 %to &amp;amp;max_grams;
&amp;amp;&amp;amp;rank_bigrams&amp;amp;ii; 
%end;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Specifically, there should not be a semi-colon on line 3. Similarly, the semi-colon in the similar place in %putt_big is incorrect.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If that works, then I give you the homework assignment to see if you can figure out why that is.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Sep 2022 14:37:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Iteratively-list-big-set-of-macro-var-for-a-proc/m-p/835623#M330347</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-09-28T14:37:15Z</dc:date>
    </item>
    <item>
      <title>Re: Iteratively list big set of macro var for a proc</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Iteratively-list-big-set-of-macro-var-for-a-proc/m-p/835627#M330350</link>
      <description>&lt;P&gt;Oh boy, what a miss. Clearly the semi-colon within the macro iterations would be repeated too, and close multiple times the var statement in the proc rank. It's a never ending learning path...Thanks Paige&lt;/P&gt;</description>
      <pubDate>Wed, 28 Sep 2022 14:48:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Iteratively-list-big-set-of-macro-var-for-a-proc/m-p/835627#M330350</guid>
      <dc:creator>dcortell</dc:creator>
      <dc:date>2022-09-28T14:48:46Z</dc:date>
    </item>
    <item>
      <title>Re: Iteratively list big set of macro var for a proc</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Iteratively-list-big-set-of-macro-var-for-a-proc/m-p/835628#M330351</link>
      <description>&lt;P&gt;First the suggestion to save all of thiseffort:&lt;/P&gt;
&lt;P&gt;Sort your TEST data set by _term_ and the use BY _term_ in proc rank for N.&lt;/P&gt;
&lt;P&gt;Then if you really need an ugly data set transpose the result, or write a report from the output of proc rank.&lt;/P&gt;
&lt;P&gt;I suspect that&lt;/P&gt;
&lt;PRE&gt;Proc sort data=test;
   by _term_;
run;

proc rank data=test groups=10 out=test2;
   by _term_;
   var n;
   ranks rank_n;
run;&lt;/PRE&gt;
&lt;P&gt;and the output from that is likely to much easier to maintain/deal with than multiple macro variables. Also this will handle values of _term_ without having to resort to name literals which won't work if you do not set the system option validvarname=any; That option might be undesirable at other places in code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Strong suggestion.&lt;/P&gt;
&lt;P&gt;Execute your Proc Rank code and manually type in two values of those names. Then show us the log from that manually run code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Exactly why are you using name literals? I don't see any values that require that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that when you have macros such as this that requires use of a macro variable not provided in the macro parameter list you are setting yourself up for debug problems when the "&amp;amp;max_grams" has not been set or has changed at a time you did not consider it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%macro putt_big;
%do ii=1 %to &amp;amp;max_grams;
&amp;amp;&amp;amp;bigrams&amp;amp;ii;  
%end;
%mend;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Sep 2022 14:51:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Iteratively-list-big-set-of-macro-var-for-a-proc/m-p/835628#M330351</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-09-28T14:51:13Z</dc:date>
    </item>
    <item>
      <title>Re: Iteratively list big set of macro var for a proc</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Iteratively-list-big-set-of-macro-var-for-a-proc/m-p/835631#M330353</link>
      <description>&lt;P&gt;I need them stored in a macro var as within the program there are steps where the full list of variables need to be called within a Macro function, like %macro(list_of_var); %do something...&lt;/P&gt;</description>
      <pubDate>Wed, 28 Sep 2022 15:02:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Iteratively-list-big-set-of-macro-var-for-a-proc/m-p/835631#M330353</guid>
      <dc:creator>dcortell</dc:creator>
      <dc:date>2022-09-28T15:02:05Z</dc:date>
    </item>
    <item>
      <title>Re: Iteratively list big set of macro var for a proc</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Iteratively-list-big-set-of-macro-var-for-a-proc/m-p/835640#M330361</link>
      <description>&lt;P&gt;Agreed on bad design, something like this is simpler.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc contents data=sashelp.cars out=test(rename=(name=_term_) where =(type=1));
run;


data add_rename;
set test;
new_name = catt('rank_', _term_);
run;

proc sql noprint;
select nliteral(_term_) , nliteral(new_name) 
into :var_list separated by " ", :rename_list separated by " " 
from add_rename;
quit;

%put &amp;amp;var_list;
%put &amp;amp;rename_list;


proc rank data=sashelp.cars out=want groups=10;
var &amp;amp;var_list.;
ranks &amp;amp;rename_list.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Sep 2022 15:27:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Iteratively-list-big-set-of-macro-var-for-a-proc/m-p/835640#M330361</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-09-28T15:27:10Z</dc:date>
    </item>
    <item>
      <title>Re: Iteratively list big set of macro var for a proc</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Iteratively-list-big-set-of-macro-var-for-a-proc/m-p/835642#M330363</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;It was my initial approach, but as number of variable is extensive (8K - working with ngrams), aggregating them in a unique var, I was getting error:&amp;nbsp;ERROR: The length of the value of the macro variable RANK_BIGRAMS (65540) exceeds the maximum length (65534). The value has been&lt;BR /&gt;truncated to 65534 characters.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So needed to resort to separate macro vars&lt;/P&gt;</description>
      <pubDate>Wed, 28 Sep 2022 15:31:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Iteratively-list-big-set-of-macro-var-for-a-proc/m-p/835642#M330363</guid>
      <dc:creator>dcortell</dc:creator>
      <dc:date>2022-09-28T15:31:53Z</dc:date>
    </item>
    <item>
      <title>Re: Iteratively list big set of macro var for a proc</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Iteratively-list-big-set-of-macro-var-for-a-proc/m-p/835644#M330365</link>
      <description>&lt;P&gt;Other solutions to get around this limitation of macro variable length&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Split the macro variable into N parts, then use all N parts when you call PROC RANK&lt;/LI&gt;
&lt;LI&gt;CALL EXECUTE&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Wed, 28 Sep 2022 15:35:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Iteratively-list-big-set-of-macro-var-for-a-proc/m-p/835644#M330365</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-09-28T15:35:48Z</dc:date>
    </item>
    <item>
      <title>Re: Iteratively list big set of macro var for a proc</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Iteratively-list-big-set-of-macro-var-for-a-proc/m-p/835657#M330371</link>
      <description>&lt;P&gt;If working with ngrams, ie individual words, then I'm with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;you should be using BY group processing and not having individual rows and just transpose your final results if needed.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Sep 2022 15:53:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Iteratively-list-big-set-of-macro-var-for-a-proc/m-p/835657#M330371</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-09-28T15:53:07Z</dc:date>
    </item>
  </channel>
</rss>

