<?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 query multiple tables spread across multiple SAS libraries to pull relevant columns? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-query-multiple-tables-spread-across-multiple-SAS/m-p/810500#M319609</link>
    <description>&lt;P&gt;Which means what exactly.&lt;/P&gt;
&lt;P&gt;Show the code you would want to run for ONE of the variables.&lt;/P&gt;</description>
    <pubDate>Thu, 28 Apr 2022 21:25:11 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-04-28T21:25:11Z</dc:date>
    <item>
      <title>How to query multiple tables spread across multiple SAS libraries to pull relevant columns?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-query-multiple-tables-spread-across-multiple-SAS/m-p/810482#M319603</link>
      <description>&lt;P&gt;Hi Experts,&lt;/P&gt;
&lt;P&gt;I have MULTIPLE ACTIVE libraries under Base SAS 9.4 (suppose&amp;nbsp; A to Z).&lt;/P&gt;
&lt;P&gt;For instance:&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;LibraryNames&amp;nbsp;&lt;/STRONG&gt;&lt;/U&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;STRONG&gt;&lt;U&gt;TableNames&amp;nbsp; &amp;nbsp;&lt;/U&gt;&lt;/STRONG&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;STRONG&gt;&lt;U&gt;ColumnNames&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Covid_19&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;patient_visit_info&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;visit_date&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Obesity&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; patient_info&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;patient_visit_date&lt;/P&gt;
&lt;P&gt;Diabetes&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; visitor_info&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;visit_date_info&lt;/P&gt;
&lt;P&gt;Assume there are hundreds of tables which contain columns containing DATE in them. I have limited knowledge of&amp;nbsp; pulling relevant columns from multiple TABLES (via&amp;nbsp; PROC SQL via&amp;nbsp; LIKE operator in SQL-&amp;nbsp; '...where ColumnNames LIKE % DATE% ...'&amp;nbsp; ).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But I don't know which LIBRARY or&amp;nbsp; TABLES they are in.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could you please&amp;nbsp; suggest methods/ways to query MULTIPLE&amp;nbsp; LIBRARIES at one go to&amp;nbsp; find TABLES and pull&amp;nbsp; COLUMNS&amp;nbsp; of interest ?&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would appreciate any codes, relevant links and&amp;nbsp; tips on the same.&lt;/P&gt;
&lt;P&gt;SASsy DATA STEP is preferred over resource consuming PROC SQL as far as possible &lt;span class="lia-unicode-emoji" title=":grinning_face:"&gt;😀&lt;/span&gt;.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Apr 2022 20:28:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-query-multiple-tables-spread-across-multiple-SAS/m-p/810482#M319603</guid>
      <dc:creator>inquistive</dc:creator>
      <dc:date>2022-04-28T20:28:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to query multiple tables spread across multiple SAS libraries to pull relevant columns?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-query-multiple-tables-spread-across-multiple-SAS/m-p/810486#M319605</link>
      <description>&lt;P&gt;Actually you should start with PROC SQL because that is where the DICTIONARY metadata library lives.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In particular DICTIONARY.COLUMNS will let you find the NAME of all of the variables in all of the MEMBERs in all of the LIBREFs.&lt;/P&gt;
&lt;P&gt;For example you might look for variable that have the string DATE in their name.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table datevars as
  select *
  from dictionary.columns
  where upcase(name) like '%DATE%'
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or perhaps look for variables that have DATE type format attached to them.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table datevars as
  select *
  from dictionary.columns
  where  'date' = fmtinfo(prxchange('s/\d*\.*\d*$//',-1,trim(format)),'cat')
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Once you have the list of variables you can use it to do whatever you want, but it is not at all clear to me what you want.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Apr 2022 20:39:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-query-multiple-tables-spread-across-multiple-SAS/m-p/810486#M319605</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-04-28T20:39:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to query multiple tables spread across multiple SAS libraries to pull relevant columns?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-query-multiple-tables-spread-across-multiple-SAS/m-p/810492#M319606</link>
      <description>&lt;P&gt;Note if you use PROC CONTENTS to get the list of variable names then finding the format category is a lot easier because the format name is in a field of its own without the digits and period appended.&lt;/P&gt;
&lt;P&gt;But then you would have to query each libref separately.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc contents data=covid19._all_ noprint out=content1;
run;

data datevar1;
  set content1;
  where 'date'=fmtinfo(format,'cat');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 Apr 2022 20:49:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-query-multiple-tables-spread-across-multiple-SAS/m-p/810492#M319606</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-04-28T20:49:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to query multiple tables spread across multiple SAS libraries to pull relevant columns?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-query-multiple-tables-spread-across-multiple-SAS/m-p/810496#M319608</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;,&lt;BR /&gt;Thank you for the quick reply and code. Sorry for being unclear. These  codes seem to pull the metadata of columns containing ...date...My objective is to pull the values from the ...date...columns for further analysis.</description>
      <pubDate>Thu, 28 Apr 2022 20:57:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-query-multiple-tables-spread-across-multiple-SAS/m-p/810496#M319608</guid>
      <dc:creator>inquistive</dc:creator>
      <dc:date>2022-04-28T20:57:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to query multiple tables spread across multiple SAS libraries to pull relevant columns?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-query-multiple-tables-spread-across-multiple-SAS/m-p/810500#M319609</link>
      <description>&lt;P&gt;Which means what exactly.&lt;/P&gt;
&lt;P&gt;Show the code you would want to run for ONE of the variables.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Apr 2022 21:25:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-query-multiple-tables-spread-across-multiple-SAS/m-p/810500#M319609</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-04-28T21:25:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to query multiple tables spread across multiple SAS libraries to pull relevant columns?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-query-multiple-tables-spread-across-multiple-SAS/m-p/810504#M319610</link>
      <description>&lt;P&gt;Sounds like you want to scan the three libraries mentioned for any variable that contains the word date and then run a proc freq on that variable?&lt;/P&gt;
&lt;P&gt;Do you care about the variable type?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are there any variables that have DT instead of Date, ie Patient_Admit_Dt?&lt;/P&gt;
&lt;P&gt;And what about variables that have a date format but not date in the name?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It would help if you clarified exactly what you want as output as well.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Apr 2022 22:14:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-query-multiple-tables-spread-across-multiple-SAS/m-p/810504#M319610</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-04-28T22:14:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to query multiple tables spread across multiple SAS libraries to pull relevant columns?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-query-multiple-tables-spread-across-multiple-SAS/m-p/811052#M319893</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) Do you care about the variable type?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes. I am only interested in the variable with date type/format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) Are there any variables that have DT instead of Date, i.e Patient_Admit_Dt?&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Yes. The libraries have some (these are date type/format) ending in ..._DT&amp;nbsp; as well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3. And what about variables that have a date format but not date in the name?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;I am only focused on the variables that apparently have date values only. I am not worried about the (rest of the) variables that may have date format/type data but no date in name.&lt;/P&gt;
&lt;P&gt;4. It would help if you clarified exactly what you want as output as well.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Suppose, I have three libraries and there are 300 tables that have multiple date type/format variables&amp;nbsp; pulled from various sources maintained (entered)by various end users increasing the propensity of data entry errors and typos. For instances, a user enters 05/02/3022 (intent was to enter 05-02-2022). Another user enters 05/02/4000. The database does not prevent the user from entering 05/02/3022 or&amp;nbsp; 05/02/4000 as&amp;nbsp; they are in correct date type/format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;While&amp;nbsp; limiting the dates from ...2001... to ...2022... (current year, month, day etc.) for analysis, the records with 05/02/3022 or 05/02/4000 will be apparently excluded resulting in the incorrect analysis.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hence, I need to catch the unusual (at least for my programming purpose) dates and correct them before analysis (and alert the leaders of the pertinent teams on this and have them correct these sorts of errors&amp;nbsp; in the source systems&amp;nbsp; as&amp;nbsp; appropriate ).&lt;/P&gt;
&lt;P&gt;In short, I need to catch/identify the odd (out of scope from my program/analysis) dates, if any. Simply we can&amp;nbsp; say it's an &lt;EM&gt;&lt;STRONG&gt;anomaly detection&lt;/STRONG&gt;&lt;/EM&gt; phase.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 May 2022 12:44:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-query-multiple-tables-spread-across-multiple-SAS/m-p/811052#M319893</guid>
      <dc:creator>inquistive</dc:creator>
      <dc:date>2022-05-02T12:44:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to query multiple tables spread across multiple SAS libraries to pull relevant columns?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-query-multiple-tables-spread-across-multiple-SAS/m-p/811094#M319922</link>
      <description>&lt;UL&gt;
&lt;LI&gt;Find all column/table names with DATE or DT&lt;/LI&gt;
&lt;/UL&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table date_variables as
select *
from sashelp.vcolumn
where name like ('%DATE%') or name like ('%DT%');
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That will give you the list of tables.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now, once you've figured out what analysis you want to do on each table/column you can do the following.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm assuming now you just want to run a proc freq on the data to see the year(2022) and yearmonth (202201) of the data.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Customize this to what you need - this part is up to you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro analyze_date_vars(libname=, memname=, name=);

Title "Year analysis of Library: &amp;amp;libname. , Table: &amp;amp;memname., Variable: &amp;amp;name.";
proc freq data=&amp;amp;libname..&amp;amp;memname;
table &amp;amp;name;
format &amp;amp;name year.;
run;

Title "YearMonth analysis of Library: &amp;amp;libname. , Table: &amp;amp;memname., Variable: &amp;amp;name.";
proc freq data=&amp;amp;libname..&amp;amp;memname;
table &amp;amp;name;
format &amp;amp;name yymmn6.;
run;

%mend;



&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you can run the summary for each variable using CALL EXECUTE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data run_reports;
set date_variables;

str = catt('%analyze_date_vars(libname='
             libname, 
            ', memname=',
             memname,
            ', name=',
             name,
             ');'
             );

call execute(str);

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Untested, as no sample data.&lt;/P&gt;
&lt;P&gt;Good Luck.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 May 2022 16:55:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-query-multiple-tables-spread-across-multiple-SAS/m-p/811094#M319922</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-05-02T16:55:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to query multiple tables spread across multiple SAS libraries to pull relevant columns?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-query-multiple-tables-spread-across-multiple-SAS/m-p/811116#M319923</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;I very much&amp;nbsp; appreciate your kind support.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You are an inspirational mentor&amp;nbsp; who can read between the words and provide very useful tips, hints &amp;amp; codes without being too demanding (to show the actual logs or programs, which often are company's proprietary data, and hence not to be shared publicly.) once the scenario is well explained.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Babu&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 May 2022 18:16:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-query-multiple-tables-spread-across-multiple-SAS/m-p/811116#M319923</guid>
      <dc:creator>inquistive</dc:creator>
      <dc:date>2022-05-02T18:16:46Z</dc:date>
    </item>
  </channel>
</rss>

