<?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 a libname for variable and contents in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/query-a-libname-for-variable-and-contents/m-p/729674#M227123</link>
    <description>&lt;P&gt;If you can be sure that the column attributes (especially type and length) are the same in all source ds then you could also do something like below (code not tested) in case you want to create data which you can report on in a single report.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select cats(libname,'.',memname,'(keep=',name,')') into :ds_list separated by ' '
,memname as table_name
from dictionary.columns
where libname = 'LAKEP'
/*and user_id in ('1LB','402','CM7','EI9','JS2','J8M',
'KS7','MB2','NR4','VG5') or username
in ('1LB','402','CM7','EI9','JS2','J8M',
'KS7','MB2','NR4','VG5')*/
;
quit;

data all;
  length _source_ds sourc_ds $41;
  set &amp;amp;ds_list inds=_source_ds;
  source_ds=_source_ds;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 28 Mar 2021 23:38:51 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2021-03-28T23:38:51Z</dc:date>
    <item>
      <title>query a libname for variable and contents</title>
      <link>https://communities.sas.com/t5/SAS-Programming/query-a-libname-for-variable-and-contents/m-p/729656#M227108</link>
      <description>&lt;P&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table columns as&lt;BR /&gt;select name as variable&lt;BR /&gt;,memname as table_name&lt;BR /&gt;from dictionary.columns&lt;BR /&gt;where libname = 'LAKEP'&lt;BR /&gt;/*and user_id in ('1LB','402','CM7','EI9','JS2','J8M',&lt;BR /&gt;'KS7','MB2','NR4','VG5') or username &lt;BR /&gt;in ('1LB','402','CM7','EI9','JS2','J8M',&lt;BR /&gt;'KS7','MB2','NR4','VG5')*/&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The above code will return the variable columns for a particular libname.&amp;nbsp; I know you cannot run this code however as a general question, is it possible to do a query of an entire libname and return the contents of a particular variable?&amp;nbsp; As you can I commented out user_id and username.&amp;nbsp; i am trying to determine If I can isolate particular user_id.&amp;nbsp; Currently I am performing dataset queries on each individual table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 28 Mar 2021 18:57:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/query-a-libname-for-variable-and-contents/m-p/729656#M227108</guid>
      <dc:creator>Q1983</dc:creator>
      <dc:date>2021-03-28T18:57:31Z</dc:date>
    </item>
    <item>
      <title>Re: query a libname for variable and contents</title>
      <link>https://communities.sas.com/t5/SAS-Programming/query-a-libname-for-variable-and-contents/m-p/729662#M227114</link>
      <description>&lt;P&gt;Generally querying each set is going to be the approach. If you are looking for a way to reduce the code needed then&lt;/P&gt;
&lt;P&gt;Put the list of data sets that actually have variable named user_id such as&lt;/P&gt;
&lt;PRE&gt;proc sql;
   create table temp as
   select libname, memname 
  from dictionary.columns
  where libname = 'LAKEP'
  and upcase(name)='USER_ID'
  ;
quit;
&lt;/PRE&gt;
&lt;P&gt;Use that data set to select the records you want such as with Call execute&lt;/P&gt;
&lt;PRE&gt;data _null_;
    set temp;
    call execute ("data work.memname;")
    call execute ("set "||catx('.',libname,memname)||";");
    call execute ("where user_id in (&amp;lt;your list of values goes here&amp;gt;);";
    call execute ("run;")
run;&lt;/PRE&gt;
&lt;P&gt;I'm taking a short way out using work.memname. You could use the values of Memname and any string functions you want ot create a different data set name.&lt;/P&gt;</description>
      <pubDate>Sun, 28 Mar 2021 20:27:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/query-a-libname-for-variable-and-contents/m-p/729662#M227114</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-03-28T20:27:02Z</dc:date>
    </item>
    <item>
      <title>Re: query a libname for variable and contents</title>
      <link>https://communities.sas.com/t5/SAS-Programming/query-a-libname-for-variable-and-contents/m-p/729664#M227116</link>
      <description>&lt;P&gt;You can use the COLUMNS Dictionary table to find what tables user_id and username are in, then you could use the FREQ procedure to profile the distinct values in these columns in each of those tables. Here is an example of this approach:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table tables as
select  libname
       ,memname 
from dictionary.columns
where libname = 'SASHELP'
and name = 'NAME';
quit;

data _null_;
  set tables;
  call execute('proc freq data = ' !! libname !! '.' !! memname !! ' (obs = 20); table name; run;');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 28 Mar 2021 20:46:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/query-a-libname-for-variable-and-contents/m-p/729664#M227116</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2021-03-28T20:46:40Z</dc:date>
    </item>
    <item>
      <title>Re: query a libname for variable and contents</title>
      <link>https://communities.sas.com/t5/SAS-Programming/query-a-libname-for-variable-and-contents/m-p/729674#M227123</link>
      <description>&lt;P&gt;If you can be sure that the column attributes (especially type and length) are the same in all source ds then you could also do something like below (code not tested) in case you want to create data which you can report on in a single report.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select cats(libname,'.',memname,'(keep=',name,')') into :ds_list separated by ' '
,memname as table_name
from dictionary.columns
where libname = 'LAKEP'
/*and user_id in ('1LB','402','CM7','EI9','JS2','J8M',
'KS7','MB2','NR4','VG5') or username
in ('1LB','402','CM7','EI9','JS2','J8M',
'KS7','MB2','NR4','VG5')*/
;
quit;

data all;
  length _source_ds sourc_ds $41;
  set &amp;amp;ds_list inds=_source_ds;
  source_ds=_source_ds;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 28 Mar 2021 23:38:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/query-a-libname-for-variable-and-contents/m-p/729674#M227123</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-03-28T23:38:51Z</dc:date>
    </item>
  </channel>
</rss>

