<?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: Searching for a single observation among multiple tables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Searching-for-a-single-observation-among-multiple-tables/m-p/203617#M266985</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;Sorry for the confusion.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;I need to search all variables within all data sets, but I do know the library it's in.&amp;nbsp; The observation will be character, and not a date.&amp;nbsp; If it appears more than once, I'd like to see all variables and datasets that it appears in.&amp;nbsp; It's ok if it's just part of a text variable.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 15 Jul 2015 18:26:37 GMT</pubDate>
    <dc:creator>EricM0628</dc:creator>
    <dc:date>2015-07-15T18:26:37Z</dc:date>
    <item>
      <title>Searching for a single observation among multiple tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Searching-for-a-single-observation-among-multiple-tables/m-p/203613#M266981</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Is it possible to search multiple tables within a database for a single observation value (using Enterprise Guide 5.1)?&amp;nbsp; I have a newly connected database that I'm trying to map, and I'm having difficulty finding a specific variable.&amp;nbsp; I have a report from the front end that provides some data, and I'd like to search all of the tables within the database for a single value.&amp;nbsp; In order to get the report schema I'll have to go to the vendor, which has a cost associated to it.&amp;nbsp; So, I'm attempting to avoid going down that road.&amp;nbsp; I appreciate any suggestions.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jul 2015 14:49:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Searching-for-a-single-observation-among-multiple-tables/m-p/203613#M266981</guid>
      <dc:creator>EricM0628</dc:creator>
      <dc:date>2015-07-15T14:49:01Z</dc:date>
    </item>
    <item>
      <title>Re: Searching for a single observation among multiple tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Searching-for-a-single-observation-among-multiple-tables/m-p/203614#M266982</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Assuming you know which library you can run the following code to table names (I don't know the tasks for EG and don't have 5.1)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select memname&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from dictionary.columns&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where libname='LIB' and upcase(name)="YOURVARIABLENAMEINCAPS";&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;Replace LIB with your library name. If you don't know the library then leave out the Libname part and add " , Libname" to the select clause.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jul 2015 15:56:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Searching-for-a-single-observation-among-multiple-tables/m-p/203614#M266982</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2015-07-15T15:56:19Z</dc:date>
    </item>
    <item>
      <title>Re: Searching for a single observation among multiple tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Searching-for-a-single-observation-among-multiple-tables/m-p/203615#M266983</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the quick reply, but I'm actually looking for an observation value.&amp;nbsp; I've been able to pull all of the variable names, but that isn't helping me find the correct one.&amp;nbsp;&amp;nbsp; I need to find the table and variable that stores a particular observation.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jul 2015 16:02:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Searching-for-a-single-observation-among-multiple-tables/m-p/203615#M266983</guid>
      <dc:creator>EricM0628</dc:creator>
      <dc:date>2015-07-15T16:02:03Z</dc:date>
    </item>
    <item>
      <title>Re: Searching for a single observation among multiple tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Searching-for-a-single-observation-among-multiple-tables/m-p/203616#M266984</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You title says one thing then the text of your post included&lt;/P&gt;&lt;PRE __jive_macro_name="quote" class="jive_text_macro jive_macro_quote"&gt;
&lt;P&gt;and I'm having difficulty finding a specific variable&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;so I started with the easy part.&lt;/P&gt;&lt;P&gt;Is this value in a known variable or do you have to search all variables in all data sets? Do you know which library it should be in?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is it character or numeric? If it is a date do you know if dates were imported as SAS date valued variables or character?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What if the value appears more than once? Do you want a list of all variables and datasets?&lt;/P&gt;&lt;P&gt;If the value is character are you looking for an exact match, i.e. case, leading blanks, or can it be part just part of text variable?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jul 2015 17:44:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Searching-for-a-single-observation-among-multiple-tables/m-p/203616#M266984</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2015-07-15T17:44:28Z</dc:date>
    </item>
    <item>
      <title>Re: Searching for a single observation among multiple tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Searching-for-a-single-observation-among-multiple-tables/m-p/203617#M266985</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;Sorry for the confusion.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;I need to search all variables within all data sets, but I do know the library it's in.&amp;nbsp; The observation will be character, and not a date.&amp;nbsp; If it appears more than once, I'd like to see all variables and datasets that it appears in.&amp;nbsp; It's ok if it's just part of a text variable.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jul 2015 18:26:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Searching-for-a-single-observation-among-multiple-tables/m-p/203617#M266985</guid>
      <dc:creator>EricM0628</dc:creator>
      <dc:date>2015-07-15T18:26:37Z</dc:date>
    </item>
    <item>
      <title>Re: Searching for a single observation among multiple tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Searching-for-a-single-observation-among-multiple-tables/m-p/203618#M266986</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This seems to work for me:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let searchval = 1003349;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* AN EXAMPLE VALUE, DO NOT USE QUOTES FOR YOURS*/&lt;/P&gt;&lt;P&gt;/* the macro variable is so that I use the same in two places*/&lt;/P&gt;&lt;P&gt;/* this gets the names of the data sets in the specified library (use UPPER case for the name) with&lt;/P&gt;&lt;P&gt;at least one character variable long enough to hold the string specified in SEARCHVAL*/&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; create table work.datasets as&lt;BR /&gt;&amp;nbsp;&amp;nbsp; select distinct memname&lt;BR /&gt;&amp;nbsp;&amp;nbsp; from ( select * from dictionary.columns&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where libname='LIBRARY' and type='char'&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; and length("&amp;amp;searchval") le length)&lt;BR /&gt;&amp;nbsp;&amp;nbsp; ;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;/* this is a brute force search of a data set, the default is to seach the library you specify above if you&lt;/P&gt;&lt;P&gt;replace the value in the macro definition. Hardcoding the name of the output file reference isn't best practice,&lt;/P&gt;&lt;P&gt;wouldn't be hard to add another parameter*/&lt;/P&gt;&lt;P&gt;%macro findit (lib=LIBRARY,dataset=,value=);&lt;BR /&gt;data _null_;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; set &amp;amp;lib..&amp;amp;dataset;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; file tables mod ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; array c _character_;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; length name $ 32 ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; do i = 1 to dim(c);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; name = vname(c&lt;I&gt;);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if index( c&lt;I&gt;,strip("&amp;amp;value")) &amp;gt; 0 then&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; put "Value: &amp;amp;value" +4 "Dataset: &amp;amp;dataset" +4 "Record:" _n_ +4"Variable: " name;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; end;&lt;BR /&gt;run;&lt;BR /&gt;%mend;&lt;/I&gt;&lt;/I&gt;&lt;/P&gt;&lt;P&gt;/* specify the name of the output file path and name in a filename statement*/&lt;/P&gt;&lt;P&gt;filename tables "path\tables.txt"&amp;nbsp; mod;&lt;/P&gt;&lt;P&gt;/* loop through the datasets found above and call the search macro for each*/&lt;BR /&gt;data _null_;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; set work.datasets;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; call execute('%findit(dataset='||memname||',value='||"&amp;amp;searchval"||')');&lt;BR /&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jul 2015 20:36:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Searching-for-a-single-observation-among-multiple-tables/m-p/203618#M266986</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2015-07-15T20:36:12Z</dc:date>
    </item>
    <item>
      <title>Re: Searching for a single observation among multiple tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Searching-for-a-single-observation-among-multiple-tables/m-p/203619#M266987</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Just a suggestion ...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Don't print out all occurrences found.&amp;nbsp; If the user enters the wrong string, you can end up trying to print millions of records.&amp;nbsp; Just put them into a data set and print later if warranted.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jul 2015 22:42:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Searching-for-a-single-observation-among-multiple-tables/m-p/203619#M266987</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-07-15T22:42:03Z</dc:date>
    </item>
    <item>
      <title>Re: Searching for a single observation among multiple tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Searching-for-a-single-observation-among-multiple-tables/m-p/203620#M266988</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks, it looks like this worked.&amp;nbsp; I appreciate the assistance.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jul 2015 14:30:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Searching-for-a-single-observation-among-multiple-tables/m-p/203620#M266988</guid>
      <dc:creator>EricM0628</dc:creator>
      <dc:date>2015-07-16T14:30:57Z</dc:date>
    </item>
  </channel>
</rss>

