<?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 to stack datasets with similar names, but excludes some in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-stack-datasets-with-similar-names-but-excludes-some/m-p/706814#M217007</link>
    <description>&lt;P&gt;If you want to use lists you could use an explicit list like&lt;/P&gt;
&lt;P&gt;set dataset_01 - dataset_05;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BUT you can't have gaps in the number sequence. If you do have gaps you code around with&lt;/P&gt;
&lt;P&gt;set dataset_01 - dataset_04&amp;nbsp;&amp;nbsp; dataset_06-dataset_12;&lt;/P&gt;
&lt;P&gt;or similar.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another approach might be to use the simple list and drop the sets whose names don't match the pattern&lt;/P&gt;
&lt;P&gt;possibly based on the length of names or other pattern.&amp;nbsp; The INDSNAME set option creates an automatic variable with the library.dataset name the current&amp;nbsp; observation is from:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;set dataset_:&amp;nbsp; indsname=source;&lt;/P&gt;
&lt;P&gt;if length(scan(source,2,'.')) ne 10;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This could be pretty time intensive if&amp;nbsp; lots of records are involved.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 17 Dec 2020 23:00:42 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2020-12-17T23:00:42Z</dc:date>
    <item>
      <title>How to stack datasets with similar names, but excludes some</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-stack-datasets-with-similar-names-but-excludes-some/m-p/706810#M217003</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have many datasets with similar suffix such as:&lt;/P&gt;&lt;P&gt;dataset_01&lt;/P&gt;&lt;P&gt;dataset_02&lt;/P&gt;&lt;P&gt;dataset_03&lt;/P&gt;&lt;P&gt;dataset_03_v2&lt;/P&gt;&lt;P&gt;dataset_04&lt;/P&gt;&lt;P&gt;dataset_05_v2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to stack all of them together excluding the ones with _v2, which cannot be achieved by just using&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set dataset_: ;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there an efficient way to exclude by conditions?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Dec 2020 22:03:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-stack-datasets-with-similar-names-but-excludes-some/m-p/706810#M217003</guid>
      <dc:creator>lydiawawa</dc:creator>
      <dc:date>2020-12-17T22:03:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to stack datasets with similar names, but excludes some</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-stack-datasets-with-similar-names-but-excludes-some/m-p/706814#M217007</link>
      <description>&lt;P&gt;If you want to use lists you could use an explicit list like&lt;/P&gt;
&lt;P&gt;set dataset_01 - dataset_05;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BUT you can't have gaps in the number sequence. If you do have gaps you code around with&lt;/P&gt;
&lt;P&gt;set dataset_01 - dataset_04&amp;nbsp;&amp;nbsp; dataset_06-dataset_12;&lt;/P&gt;
&lt;P&gt;or similar.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another approach might be to use the simple list and drop the sets whose names don't match the pattern&lt;/P&gt;
&lt;P&gt;possibly based on the length of names or other pattern.&amp;nbsp; The INDSNAME set option creates an automatic variable with the library.dataset name the current&amp;nbsp; observation is from:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;set dataset_:&amp;nbsp; indsname=source;&lt;/P&gt;
&lt;P&gt;if length(scan(source,2,'.')) ne 10;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This could be pretty time intensive if&amp;nbsp; lots of records are involved.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Dec 2020 23:00:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-stack-datasets-with-similar-names-but-excludes-some/m-p/706814#M217007</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-12-17T23:00:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to stack datasets with similar names, but excludes some</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-stack-datasets-with-similar-names-but-excludes-some/m-p/706817#M217010</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/30435"&gt;@lydiawawa&lt;/a&gt;&amp;nbsp; My recommendation would be is to read dictionary tables and filter into a macro variable-&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data
dataset_01

dataset_02

dataset_03

dataset_03_v2

dataset_04

dataset_05_v2;
x=1;
y=2;
run;

proc sql;
 select memname into :dsn separated by ' '
 from dictionary.tables
 where libname='WORK' and upcase(memname) like ('DATASET_%')
 AND countw(memname,'_')=2;
quit;

data want;
 set &amp;amp;dsn;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;One caveat though is there is a limitation of 64K bytes that a macro variable can hold as length. In that case switching to CALL EXECUTE would be idea or there are other boring ways to generate SAS statements and CALL using %INCLUDE&lt;/P&gt;</description>
      <pubDate>Fri, 18 Dec 2020 00:31:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-stack-datasets-with-similar-names-but-excludes-some/m-p/706817#M217010</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-12-18T00:31:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to stack datasets with similar names, but excludes some</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-stack-datasets-with-similar-names-but-excludes-some/m-p/706819#M217011</link>
      <description>&lt;P&gt;You could use the indsname= option on the SET statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set dataset_: indsname=dsn;
  if scan(upcase(dsn),3,'_')='V2' then delete;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But that requires doing the if test on each and every incoming observation.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It might be better to customize the dataset list prior to the data step using proc sql dictionary.tables:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
  select distinct memname into :dsnlist separated by ' '
  from dictionary.tables where upcase(memname) like "DATASET_%"
  and scan(upcase(memname),3,'_') NE 'V2';
quit;

data want;
  set &amp;amp;dsnlist;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This option doesn't have to do a record-by-record check on the incoming dataset name.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Dec 2020 22:36:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-stack-datasets-with-similar-names-but-excludes-some/m-p/706819#M217011</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-12-17T22:36:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to stack datasets with similar names, but excludes some</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-stack-datasets-with-similar-names-but-excludes-some/m-p/706832#M217017</link>
      <description>&lt;P&gt;A bit off-topic but it is good practice to name your datasets based on the contents and not just generic names like dataset. It will likely simplify dataset management as well.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Dec 2020 23:08:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-stack-datasets-with-similar-names-but-excludes-some/m-p/706832#M217017</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2020-12-17T23:08:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to stack datasets with similar names, but excludes some</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-stack-datasets-with-similar-names-but-excludes-some/m-p/706835#M217018</link>
      <description>the tables are not in work library, how do I set the datasets in dsn with a library name?</description>
      <pubDate>Thu, 17 Dec 2020 23:51:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-stack-datasets-with-similar-names-but-excludes-some/m-p/706835#M217018</guid>
      <dc:creator>lydiawawa</dc:creator>
      <dc:date>2020-12-17T23:51:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to stack datasets with similar names, but excludes some</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-stack-datasets-with-similar-names-but-excludes-some/m-p/706838#M217019</link>
      <description>the tables in dsnlist are not in work library, how do I set those datasets by pointing to a library?&lt;BR /&gt;&lt;BR /&gt;I tried&lt;BR /&gt;data want;&lt;BR /&gt;set mylib1.&amp;amp;dsnlist;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;Only first dataset was grabbed from the library</description>
      <pubDate>Thu, 17 Dec 2020 23:54:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-stack-datasets-with-similar-names-but-excludes-some/m-p/706838#M217019</guid>
      <dc:creator>lydiawawa</dc:creator>
      <dc:date>2020-12-17T23:54:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to stack datasets with similar names, but excludes some</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-stack-datasets-with-similar-names-but-excludes-some/m-p/706847#M217021</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/30435"&gt;@lydiawawa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;the tables are not in work library, how do I set the datasets in dsn with a library name?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Put your library name in the place of "WORK". If in the dictionary table use uppercase spelling as that is how the libname is stored.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Dec 2020 00:18:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-stack-datasets-with-similar-names-but-excludes-some/m-p/706847#M217021</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-12-18T00:18:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to stack datasets with similar names, but excludes some</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-stack-datasets-with-similar-names-but-excludes-some/m-p/706850#M217024</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/30435"&gt;@lydiawawa&lt;/a&gt;&amp;nbsp; &amp;nbsp;Please point to the name of the library where your datasets reside instead of WORK. Mine was just a mere example of logic/approach&lt;/P&gt;</description>
      <pubDate>Fri, 18 Dec 2020 00:26:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-stack-datasets-with-similar-names-but-excludes-some/m-p/706850#M217024</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-12-18T00:26:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to stack datasets with similar names, but excludes some</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-stack-datasets-with-similar-names-but-excludes-some/m-p/706856#M217025</link>
      <description>No, this is not what I was asking, I tried to set the datasets with names stored in the macro variables, dsn, but the way it is written only considered the datasets stored in WORK folder.</description>
      <pubDate>Fri, 18 Dec 2020 01:02:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-stack-datasets-with-similar-names-but-excludes-some/m-p/706856#M217025</guid>
      <dc:creator>lydiawawa</dc:creator>
      <dc:date>2020-12-18T01:02:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to stack datasets with similar names, but excludes some</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-stack-datasets-with-similar-names-but-excludes-some/m-p/706857#M217026</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/30435"&gt;@lydiawawa&lt;/a&gt;&amp;nbsp; I see your point. You need to concatenate libname and memname like-&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;select catx('.',libname,memname) into :dsn separated by ' '&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data
dataset_01

dataset_02

dataset_03

dataset_03_v2

dataset_04

dataset_05_v2;
x=1;
y=2;
run;

proc sql;
 select catx('.',libname,memname) into :dsn separated by ' '
 from dictionary.tables
 where libname='WORK' and upcase(memname) like ('DATASET_%')
 AND countw(memname,'_')=2;
quit;

data want;
 set &amp;amp;dsn;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 18 Dec 2020 01:22:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-stack-datasets-with-similar-names-but-excludes-some/m-p/706857#M217026</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-12-18T01:22:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to stack datasets with similar names, but excludes some</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-stack-datasets-with-similar-names-but-excludes-some/m-p/706870#M217034</link>
      <description>&lt;P&gt;Create the data set name list as follows&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
  select catx('.', libname, memname) into :dsnlist separated by ' '
  from dictionary.tables 
  where
    libname = "your-libname-in-UPPERCASE" and
    upcase(memname) like "DATASET_%" and
    scan(upcase(memname),3,'_') NE 'V2'
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And use the list as follows&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;SET &amp;amp;dsnlist;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 18 Dec 2020 03:50:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-stack-datasets-with-similar-names-but-excludes-some/m-p/706870#M217034</guid>
      <dc:creator>RichardDeVen</dc:creator>
      <dc:date>2020-12-18T03:50:52Z</dc:date>
    </item>
  </channel>
</rss>

