<?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: Concentrate datasets using macro variable in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Concentrate-datasets-using-macro-variable/m-p/342802#M22707</link>
    <description>The code's beautiful. Thank you.</description>
    <pubDate>Tue, 21 Mar 2017 01:24:30 GMT</pubDate>
    <dc:creator>ayin</dc:creator>
    <dc:date>2017-03-21T01:24:30Z</dc:date>
    <item>
      <title>Concentrate datasets using macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Concentrate-datasets-using-macro-variable/m-p/342790#M22702</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Users specify a macro variable */
%let Name = 0 test All
%let Num_Name = %sysfunc(countw(&amp;amp;Name)); /* which is 3 */
%do _z=1 %to &amp;amp;Num_Name;
%let File_Name = %scan(&amp;amp;Name,&amp;amp;_z);

/* datasets have names like */
lib.data_&amp;amp;File_Name

/* in this case, the dataset names would be
lib.data_0
lib.data_test
lib.data_All */&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;These three datasets have the same columns:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* e.g. one dataset would look like */
Type _1 _2 _3 Order
A     0  0  0  1&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I would like to &lt;U&gt;concentrate these datasets, and create a final dataset&lt;/U&gt;: lib.data_final (without hardcoding it)&lt;/P&gt;&lt;P&gt;and then rows arranged in ascending order based on the column 'Order'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Tried using a loop:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%do _z=1 %to &amp;amp;Num_Name;
%let File_Name = %scan(&amp;amp;Name,&amp;amp;_z);

data lib.want;
set lib.want lib.data_&amp;amp;File_Name;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;However reported an error: lib.want.data does not exist.&lt;/P&gt;</description>
      <pubDate>Mon, 20 Mar 2017 23:31:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Concentrate-datasets-using-macro-variable/m-p/342790#M22702</guid>
      <dc:creator>ayin</dc:creator>
      <dc:date>2017-03-20T23:31:07Z</dc:date>
    </item>
    <item>
      <title>Re: Concentrate datasets using macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Concentrate-datasets-using-macro-variable/m-p/342792#M22703</link>
      <description>&lt;P&gt;By concentrate do you mean concatenate? I'm going to assume so.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We're only seeing part of your code and I suspect that the loop isn't in the correct location.&amp;nbsp;But the %DO loop should be after the SET statement and it's not clear where it's located.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would suggest an alternative though and that would be to build the name list separately by filtering the SASHELP.VTABLE and then passing that to the macro.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Mar 2017 23:41:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Concentrate-datasets-using-macro-variable/m-p/342792#M22703</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-03-20T23:41:24Z</dc:date>
    </item>
    <item>
      <title>Re: Concentrate datasets using macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Concentrate-datasets-using-macro-variable/m-p/342794#M22704</link>
      <description>&lt;P&gt;So the user gives you a list of suffixes. What about the beginning of the name? Or the libref?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let name_list =  0 test All ;
%let prefix=data_ ;
%let libref=lib ;
%let out=want ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You should first make sure the list has just one space between names. &amp;nbsp;Then it is easy to convert the list of suffixes into a list of dataset names. &amp;nbsp;No %DO loops required.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let name_list =  %sysfunc(compbl(&amp;amp;name_list)) ;
%let dslist = &amp;amp;libref..&amp;amp;prefix%sysfunc(tranwrd(&amp;amp;name_list,%str( ),%str( &amp;amp;libref..&amp;amp;prefix))) ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then if the datasets are already sorted you can just interleave them with a SET/BY.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data &amp;amp;out ;
  set &amp;amp;dslist ;
  by order ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If they are not sorted then set them together first and then use PROC SORT.&lt;/P&gt;</description>
      <pubDate>Mon, 20 Mar 2017 23:54:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Concentrate-datasets-using-macro-variable/m-p/342794#M22704</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-03-20T23:54:04Z</dc:date>
    </item>
    <item>
      <title>Re: Concentrate datasets using macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Concentrate-datasets-using-macro-variable/m-p/342795#M22705</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data lib.want;
   %do _z=1 %to &amp;amp;Num_Name;
   %let File_Name = %scan(&amp;amp;Name, &amp;amp;_z);
   set lib.data_&amp;amp;File_Name;
   %end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Tried this, but only picked up the first dataset lib.data_0; not sure why.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What the code looks like if using your approach?&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Mon, 20 Mar 2017 23:55:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Concentrate-datasets-using-macro-variable/m-p/342795#M22705</guid>
      <dc:creator>ayin</dc:creator>
      <dc:date>2017-03-20T23:55:35Z</dc:date>
    </item>
    <item>
      <title>Re: Concentrate datasets using macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Concentrate-datasets-using-macro-variable/m-p/342798#M22706</link>
      <description>&lt;P&gt;Take a look at what you get generated vs what you want:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Generated:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; lib&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;want&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
   &lt;SPAN class="token keyword"&gt;set&lt;/SPAN&gt; lib&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;data_&lt;SPAN class="token operator"&gt;0&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;BR /&gt;&lt;/SPAN&gt;   set lib.data_test;&lt;BR /&gt;   set lib.data_All;
&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What you actually want:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data lib.want;
   set lib.data_0  
         lib.data_test 
         lib.data_All;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note the differences and make the necessary changes.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use the following to help you debug in the future.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options MPRINT SYMBOLGEN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Mar 2017 00:13:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Concentrate-datasets-using-macro-variable/m-p/342798#M22706</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-03-21T00:13:50Z</dc:date>
    </item>
    <item>
      <title>Re: Concentrate datasets using macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Concentrate-datasets-using-macro-variable/m-p/342802#M22707</link>
      <description>The code's beautiful. Thank you.</description>
      <pubDate>Tue, 21 Mar 2017 01:24:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Concentrate-datasets-using-macro-variable/m-p/342802#M22707</guid>
      <dc:creator>ayin</dc:creator>
      <dc:date>2017-03-21T01:24:30Z</dc:date>
    </item>
    <item>
      <title>Re: Concentrate datasets using macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Concentrate-datasets-using-macro-variable/m-p/342850#M22709</link>
      <description>&lt;P&gt;You might want to try your macro with&lt;/P&gt;
&lt;P&gt;Let name_list = : ;&lt;/P&gt;
&lt;P&gt;That is a colon in case your font is small and hard to see.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Mar 2017 06:23:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Concentrate-datasets-using-macro-variable/m-p/342850#M22709</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-03-21T06:23:51Z</dc:date>
    </item>
  </channel>
</rss>

