<?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 to combine macro values and order tham alphabetically? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-combine-macro-values-and-order-tham-alphabetically/m-p/453985#M69922</link>
    <description>&lt;P&gt;Let's say I have (numlist,datelist, charlist are all variable lists):&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%put &amp;amp;numlist;&lt;/P&gt;&lt;P&gt;a&amp;nbsp; c e&lt;BR /&gt;%put &amp;amp;datelist;&lt;/P&gt;&lt;P&gt;b d&amp;nbsp;&lt;BR /&gt;%put &amp;amp;charlist;&lt;/P&gt;&lt;P&gt;f z&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to combine a, c, e, b, d, f, z and make an output of a string that has values of a b c d e f z so that I could feed this string into a macro to do a set of analysis on each of these variables.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I combine &amp;amp;numlist, &amp;amp;datelist, &amp;amp;charlist and order the values alphabetically?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 13 Apr 2018 17:24:51 GMT</pubDate>
    <dc:creator>gsk</dc:creator>
    <dc:date>2018-04-13T17:24:51Z</dc:date>
    <item>
      <title>How to combine macro values and order tham alphabetically?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-combine-macro-values-and-order-tham-alphabetically/m-p/453985#M69922</link>
      <description>&lt;P&gt;Let's say I have (numlist,datelist, charlist are all variable lists):&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%put &amp;amp;numlist;&lt;/P&gt;&lt;P&gt;a&amp;nbsp; c e&lt;BR /&gt;%put &amp;amp;datelist;&lt;/P&gt;&lt;P&gt;b d&amp;nbsp;&lt;BR /&gt;%put &amp;amp;charlist;&lt;/P&gt;&lt;P&gt;f z&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to combine a, c, e, b, d, f, z and make an output of a string that has values of a b c d e f z so that I could feed this string into a macro to do a set of analysis on each of these variables.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I combine &amp;amp;numlist, &amp;amp;datelist, &amp;amp;charlist and order the values alphabetically?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Apr 2018 17:24:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-combine-macro-values-and-order-tham-alphabetically/m-p/453985#M69922</guid>
      <dc:creator>gsk</dc:creator>
      <dc:date>2018-04-13T17:24:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine macro values and order tham alphabetically?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-combine-macro-values-and-order-tham-alphabetically/m-p/454013#M69929</link>
      <description>&lt;P&gt;While SAS handles this much more easily than macro language, here's how you might approach the problem using macro language.&amp;nbsp; I can't test this right now, so I'm hoping there are no glitches (always mildly dangerous using %DO %UNTIL):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;%macro reorder (list=);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp;%* Break up the list into separate macro variables;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp;%local n_vars i;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp;%let n_vars = %sysfunc(countw(&amp;amp;list));&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp;%do i=1 %to &amp;amp;n_vars;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;%local temp&amp;amp;i;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;%let temp&amp;amp;i = %scan(&amp;amp;list, &amp;amp;i);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp;%end;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp;%* Order the macro variables;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp;%local changes j tempvar;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp;%do %until (&amp;amp;changes=N);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; %let changes=N;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; %do i=2 %to &amp;amp;n_vars;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;%let j = %eval(&amp;amp;i - 1);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;%if &amp;amp;&amp;amp;temp&amp;amp;i &amp;lt; &amp;amp;&amp;amp;temp&amp;amp;j %then %do;&lt;/FONT&gt;&lt;FONT face="courier new,courier"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;%let tempvar = &amp;amp;&amp;amp;temp&amp;amp;j;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;%let temp&amp;amp;j = &amp;amp;&amp;amp;temp&amp;amp;i;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;%let temp&amp;amp;i = &amp;amp;tempvar;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;%let changes = Y;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;%end;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; %end;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp;%end;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp;%* Spit out the reordered values;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp;%do i=1 %to &amp;amp;n_vars;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;amp;&amp;amp;temp&amp;amp;i&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp;%end;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;%mend;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;This returns a list of variables in the proper order.&amp;nbsp; So you would need to call in in a program that expects to see such a list.&amp;nbsp; For example:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;%put %reorder (list=&amp;amp;numlist &amp;amp;datelist &amp;amp;charlist);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;or&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;%let newlist = %reorder (list=&amp;amp;numlist &amp;amp;datelist &amp;amp;charlist);&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Apr 2018 18:16:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-combine-macro-values-and-order-tham-alphabetically/m-p/454013#M69929</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-04-13T18:16:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine macro values and order tham alphabetically?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-combine-macro-values-and-order-tham-alphabetically/m-p/454016#M69930</link>
      <description>&lt;PRE&gt;%let numlist=a c e;
%let datelist=b d;
%let charlist=f z;
data test;
  length lists $255;
  array list(7) $;
  lists=catx(' ',"&amp;amp;numlist.", "&amp;amp;datelist.","&amp;amp;charlist.");
  i=1;
  do while (scan(lists,i) ne '');
    list(i)=scan(lists,i);
    i+1;
  end;
  call sortc(of list(*));
  call symput('alllist',catx(' ',of list(*)));
run;
%put &amp;amp;alllist.;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Apr 2018 18:20:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-combine-macro-values-and-order-tham-alphabetically/m-p/454016#M69930</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2018-04-13T18:20:37Z</dc:date>
    </item>
  </channel>
</rss>

