<?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: Query multiple datasets in a library for values in another dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Query-multiple-datasets-in-a-library-for-values-in-another/m-p/603978#M175040</link>
    <description>&lt;P&gt;You want to inspect ALL the dataset in libname ABC to see if any of the datasets have variable ACC with a value you have in your work.sample dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now if your are lucky enough such that all the datasets in ABC have names beginning with &amp;nbsp; D&amp;nbsp; or T, you can do this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data mysample;
  input acc;
datalines;
63735723627
774648684
45648558585
85658676876
5865867568
run;

data acc_found;
  if _n_=1 then do;
    declare hash h (dataset:'mysample');
      h.definekey('acc');
      h.definedone();
  end;
  set abc.d: abc.t:  indsname=indsn;
  if h.find()=0;
  dsname=indsn;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which will generate a dataset with two variables: ACC and DSNAME.&amp;nbsp; It will have all the found ACC values, and the data set name(s) in which it was found.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;&amp;nbsp; The SET statement:
&lt;OL&gt;
&lt;LI&gt;the "abc:d:"&amp;nbsp; and "abc.t:" ask for all the datasets in library abc whose names begin with D or T.&amp;nbsp; So the single SET statement reads all the datasets.&lt;/LI&gt;
&lt;LI&gt;The "indsname=indsn" make a temporary variables (INDSN) with the name of the dataset for each incoming observation.&lt;/LI&gt;
&lt;/OL&gt;
&lt;/LI&gt;
&lt;LI&gt;The "if h.find()=0" is a sub-setting IF&amp;nbsp; (it has no THEN clause), and allows only observations in which the FIND method finds a matching ACC value in the hash object named h.&amp;nbsp; (The find method returns a zero when successful).&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 13 Nov 2019 21:18:47 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2019-11-13T21:18:47Z</dc:date>
    <item>
      <title>Query multiple datasets in a library for values in another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Query-multiple-datasets-in-a-library-for-values-in-another/m-p/603963#M175028</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have created a dataset that holds the names of all the datasets which are stored in a unix library. the number of datasets in that location will increase daily.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the code that I have to create that master dataset:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ods output Members=Members;&lt;BR /&gt;proc datasets library=abc memtype=data;&lt;BR /&gt;run;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I also have a sample dataset:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;63735723627&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;774648684&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;45648558585&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;85658676876&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5865867568&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I need to do is check the library to see if any of the library datasets has any of the sample dataset values in there. But I'm clueless on how to even start querying the library datasets.&amp;nbsp;How can I query all teh library datasets to look for sample dataset values?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Appreciate everyone's help and time and helping me figure this out.&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Nov 2019 20:39:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Query-multiple-datasets-in-a-library-for-values-in-another/m-p/603963#M175028</guid>
      <dc:creator>AJ_Brien</dc:creator>
      <dc:date>2019-11-13T20:39:21Z</dc:date>
    </item>
    <item>
      <title>Re: Query multiple datasets in a library for values in another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Query-multiple-datasets-in-a-library-for-values-in-another/m-p/603967#M175032</link>
      <description>&lt;P&gt;Do you at least have a variable name that you expect the value(s) to be in?&lt;/P&gt;
&lt;P&gt;Do you know if the values are character or numeric?&lt;/P&gt;
&lt;P&gt;Do any of the data sets have the same structure? Perhaps they should be appended so that the search involves fewer sets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you expect this to finish in any given time frame?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Show what you expect the output for this exercise to look like.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And SAS may not be the best tool for this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Nov 2019 20:49:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Query-multiple-datasets-in-a-library-for-values-in-another/m-p/603967#M175032</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-11-13T20:49:50Z</dc:date>
    </item>
    <item>
      <title>Re: Query multiple datasets in a library for values in another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Query-multiple-datasets-in-a-library-for-values-in-another/m-p/603970#M175035</link>
      <description>Thank you for your reply.&lt;BR /&gt;I do know the name of that variable, it's of num type. All the datasets have the same structure too. They are pretty huge in size and number that's the reason it was adviced not to append them.</description>
      <pubDate>Wed, 13 Nov 2019 20:52:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Query-multiple-datasets-in-a-library-for-values-in-another/m-p/603970#M175035</guid>
      <dc:creator>AJ_Brien</dc:creator>
      <dc:date>2019-11-13T20:52:27Z</dc:date>
    </item>
    <item>
      <title>Re: Query multiple datasets in a library for values in another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Query-multiple-datasets-in-a-library-for-values-in-another/m-p/603971#M175036</link>
      <description>For eg, the sample dataset column name is 'acc' and of type num. All the datasets in that library also have a column name 'acc' of type num. Hope this helps.</description>
      <pubDate>Wed, 13 Nov 2019 20:54:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Query-multiple-datasets-in-a-library-for-values-in-another/m-p/603971#M175036</guid>
      <dc:creator>AJ_Brien</dc:creator>
      <dc:date>2019-11-13T20:54:07Z</dc:date>
    </item>
    <item>
      <title>Re: Query multiple datasets in a library for values in another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Query-multiple-datasets-in-a-library-for-values-in-another/m-p/603978#M175040</link>
      <description>&lt;P&gt;You want to inspect ALL the dataset in libname ABC to see if any of the datasets have variable ACC with a value you have in your work.sample dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now if your are lucky enough such that all the datasets in ABC have names beginning with &amp;nbsp; D&amp;nbsp; or T, you can do this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data mysample;
  input acc;
datalines;
63735723627
774648684
45648558585
85658676876
5865867568
run;

data acc_found;
  if _n_=1 then do;
    declare hash h (dataset:'mysample');
      h.definekey('acc');
      h.definedone();
  end;
  set abc.d: abc.t:  indsname=indsn;
  if h.find()=0;
  dsname=indsn;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which will generate a dataset with two variables: ACC and DSNAME.&amp;nbsp; It will have all the found ACC values, and the data set name(s) in which it was found.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;&amp;nbsp; The SET statement:
&lt;OL&gt;
&lt;LI&gt;the "abc:d:"&amp;nbsp; and "abc.t:" ask for all the datasets in library abc whose names begin with D or T.&amp;nbsp; So the single SET statement reads all the datasets.&lt;/LI&gt;
&lt;LI&gt;The "indsname=indsn" make a temporary variables (INDSN) with the name of the dataset for each incoming observation.&lt;/LI&gt;
&lt;/OL&gt;
&lt;/LI&gt;
&lt;LI&gt;The "if h.find()=0" is a sub-setting IF&amp;nbsp; (it has no THEN clause), and allows only observations in which the FIND method finds a matching ACC value in the hash object named h.&amp;nbsp; (The find method returns a zero when successful).&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Nov 2019 21:18:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Query-multiple-datasets-in-a-library-for-values-in-another/m-p/603978#M175040</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2019-11-13T21:18:47Z</dc:date>
    </item>
    <item>
      <title>Re: Query multiple datasets in a library for values in another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Query-multiple-datasets-in-a-library-for-values-in-another/m-p/603979#M175041</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Did you try dictionary tables, you can find lot metadata information. I would query dictionary.tables if I were you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select * from dictionary.tables
where libname="SASHELP";
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Nov 2019 21:22:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Query-multiple-datasets-in-a-library-for-values-in-another/m-p/603979#M175041</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2019-11-13T21:22:46Z</dc:date>
    </item>
    <item>
      <title>Re: Query multiple datasets in a library for values in another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Query-multiple-datasets-in-a-library-for-values-in-another/m-p/603980#M175042</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/265086"&gt;@AJ_Brien&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thank you for your reply.&lt;BR /&gt;I do know the name of that variable, it's of num type. All the datasets have the same structure too. They are pretty huge in size and number that's the reason it was adviced not to append them.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Just how big is "huge"? People have quite different standards and one person's "huge" is another's "miniscule".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the sets are truly largish, such as terabyte sized then it is going to take a lot of time to search regardless.&lt;/P&gt;
&lt;P&gt;If there is only one or two variables that you are going to look for them perhaps you might want to investigate indexing the data sets on those variables. That can often improve some sorts of data retrieval.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the need is to search among arbitrary variables then be prepared to wait. A lot.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And you haven't indicated &lt;STRONG&gt;what you expect the output to look like&lt;/STRONG&gt;. What you actually need can seriously effect the approach. Do you need&amp;nbsp; a list of data sets that have any of the values, a list of data sets by value, a count of the number of times each value appears in each set, a list of all data sets with the names of all of the variables that may have any of the values ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Nov 2019 21:23:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Query-multiple-datasets-in-a-library-for-values-in-another/m-p/603980#M175042</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-11-13T21:23:03Z</dc:date>
    </item>
    <item>
      <title>Re: Query multiple datasets in a library for values in another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Query-multiple-datasets-in-a-library-for-values-in-another/m-p/603983#M175044</link>
      <description>thank you this makes so much sense.&lt;BR /&gt;&lt;BR /&gt;One question though, I tested by adding some more columns to my sample dataset, that seems to have no impact as expected since the key is defined as 'acc' and only those columns will be checked. Is that the right understanding?</description>
      <pubDate>Wed, 13 Nov 2019 21:34:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Query-multiple-datasets-in-a-library-for-values-in-another/m-p/603983#M175044</guid>
      <dc:creator>AJ_Brien</dc:creator>
      <dc:date>2019-11-13T21:34:15Z</dc:date>
    </item>
    <item>
      <title>Re: Query multiple datasets in a library for values in another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Query-multiple-datasets-in-a-library-for-values-in-another/m-p/603986#M175046</link>
      <description>another question, sorry trying to understand all that I can do with this feature. If I would like to pull another column, 'date' column for eg. from those library datasets in addition to the dataset names for all the observations that are found, is there a way to do that too?</description>
      <pubDate>Wed, 13 Nov 2019 21:40:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Query-multiple-datasets-in-a-library-for-values-in-another/m-p/603986#M175046</guid>
      <dc:creator>AJ_Brien</dc:creator>
      <dc:date>2019-11-13T21:40:42Z</dc:date>
    </item>
  </channel>
</rss>

