<?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: Is there a way to search for a value of a variable in multiple data sets? in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Is-there-a-way-to-search-for-a-value-of-a-variable-in-multiple/m-p/910435#M40742</link>
    <description>&lt;P&gt;What do you expect as result?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming that the variable "id" exists in every dataset in libname example and it is always numeric, you could write this for one dataset:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  select * 
    from example.first
      where Id = 5;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The datasets existing in one library can be retrieved from sashelp.vtable:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
  create table work.tables as
    select cats(LibName, '.', MemName) as Dataset
	  from sashelp.vtable
	    where LibName = 'EXAMPLE';
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The result is used to create a select-statement for each table:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set work.tables end=jobDone;
  
  if _n_ = 1 then do;
    call execute('proc sql;');
  end;
  
  call execute(catx(' ', 'select * from', Dataset, 'where Id = 5;'));
  
  if jobDone then do;
    call execute('quit;');
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Code is untested!&lt;/P&gt;</description>
    <pubDate>Thu, 04 Jan 2024 12:17:38 GMT</pubDate>
    <dc:creator>andreas_lds</dc:creator>
    <dc:date>2024-01-04T12:17:38Z</dc:date>
    <item>
      <title>Is there a way to search for a value of a variable in multiple data sets?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Is-there-a-way-to-search-for-a-value-of-a-variable-in-multiple/m-p/909904#M40719</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example, if I have a library "c:\example", that has 10 different datasets. I want to look for a variable ID with the value of 5. Is there a way to do this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 29 Dec 2023 16:40:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Is-there-a-way-to-search-for-a-value-of-a-variable-in-multiple/m-p/909904#M40719</guid>
      <dc:creator>cosmid</dc:creator>
      <dc:date>2023-12-29T16:40:05Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to search for a value of a variable in multiple data sets?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Is-there-a-way-to-search-for-a-value-of-a-variable-in-multiple/m-p/909909#M40720</link>
      <description>&lt;P&gt;What can you tell us about the data?&amp;nbsp; Is there a guarantee that ID exists in every data set?&amp;nbsp; Is there a guarantee that it is defined the same way (length, numeric vs. character) in every data set?&lt;/P&gt;</description>
      <pubDate>Fri, 29 Dec 2023 17:31:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Is-there-a-way-to-search-for-a-value-of-a-variable-in-multiple/m-p/909909#M40720</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2023-12-29T17:31:52Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to search for a value of a variable in multiple data sets?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Is-there-a-way-to-search-for-a-value-of-a-variable-in-multiple/m-p/910011#M40727</link>
      <description>&lt;P&gt;you could maybe write a macro to do this.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jan 2024 17:20:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Is-there-a-way-to-search-for-a-value-of-a-variable-in-multiple/m-p/910011#M40727</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2024-01-01T17:20:33Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to search for a value of a variable in multiple data sets?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Is-there-a-way-to-search-for-a-value-of-a-variable-in-multiple/m-p/910023#M40728</link>
      <description>&lt;P&gt;For small datasets, you can use call execute(), the data-driven programming skill.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc datasets lib=work nolist nowarn;
  delete final_out;
quit;

libname search "c:\example";
data _null_;
  set sashelp.vcolumn;
  where libname='SEARCH' and memtype='DATA' and upcase(name)='ID';
  by memname notsorted;

  if first.memname then call execute('
    data temp_out;
    set '||catx('.',libname,memname)||' indsname=indsname;
  ');
  call execute('
    _dsname_=indsname;
    _row_=_n_;
    _raw_value_=cats('||trim(name)||');
    _fmt_value_=strip(vvalue('||trim(name)||'));
    if _raw_value_="5";
  ');
  if last.memname then call execute('
    keep _dsname_ _row_ _raw_value_ _fmt_value_;
    run;

    proc append data=temp_out base=final_out force;
    run;
  ');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 02 Jan 2024 03:33:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Is-there-a-way-to-search-for-a-value-of-a-variable-in-multiple/m-p/910023#M40728</guid>
      <dc:creator>whymath</dc:creator>
      <dc:date>2024-01-02T03:33:09Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to search for a value of a variable in multiple data sets?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Is-there-a-way-to-search-for-a-value-of-a-variable-in-multiple/m-p/910435#M40742</link>
      <description>&lt;P&gt;What do you expect as result?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming that the variable "id" exists in every dataset in libname example and it is always numeric, you could write this for one dataset:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  select * 
    from example.first
      where Id = 5;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The datasets existing in one library can be retrieved from sashelp.vtable:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
  create table work.tables as
    select cats(LibName, '.', MemName) as Dataset
	  from sashelp.vtable
	    where LibName = 'EXAMPLE';
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The result is used to create a select-statement for each table:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set work.tables end=jobDone;
  
  if _n_ = 1 then do;
    call execute('proc sql;');
  end;
  
  call execute(catx(' ', 'select * from', Dataset, 'where Id = 5;'));
  
  if jobDone then do;
    call execute('quit;');
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Code is untested!&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jan 2024 12:17:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Is-there-a-way-to-search-for-a-value-of-a-variable-in-multiple/m-p/910435#M40742</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2024-01-04T12:17:38Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to search for a value of a variable in multiple data sets?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Is-there-a-way-to-search-for-a-value-of-a-variable-in-multiple/m-p/910565#M40751</link>
      <description>&lt;P&gt;Sorry I wasn't been clear.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;No. I just need to go through a list of datasets and check if the dataset has the variable ID and it does, then retrieve the rows where ID = 5. I wasn't sure if this was possible with SAS.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jan 2024 02:41:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Is-there-a-way-to-search-for-a-value-of-a-variable-in-multiple/m-p/910565#M40751</guid>
      <dc:creator>cosmid</dc:creator>
      <dc:date>2024-01-05T02:41:31Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to search for a value of a variable in multiple data sets?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Is-there-a-way-to-search-for-a-value-of-a-variable-in-multiple/m-p/910566#M40752</link>
      <description>Why it only works on small datasets? I didn't know about sashelp.vcolumn and the call execute. I wlll do more research to fully understand the code. Thank you!</description>
      <pubDate>Fri, 05 Jan 2024 02:47:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Is-there-a-way-to-search-for-a-value-of-a-variable-in-multiple/m-p/910566#M40752</guid>
      <dc:creator>cosmid</dc:creator>
      <dc:date>2024-01-05T02:47:30Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to search for a value of a variable in multiple data sets?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Is-there-a-way-to-search-for-a-value-of-a-variable-in-multiple/m-p/910567#M40753</link>
      <description>Thanks for breaking up the code into sections. It is much easier to see how they work that way. I will do more research to learn about the sashelp.vtable and call execute. &lt;BR /&gt;Where did you guys learn the call execute from? Is there another SAS certification other than Base and Advanced? Thanks!</description>
      <pubDate>Fri, 05 Jan 2024 02:50:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Is-there-a-way-to-search-for-a-value-of-a-variable-in-multiple/m-p/910567#M40753</guid>
      <dc:creator>cosmid</dc:creator>
      <dc:date>2024-01-05T02:50:10Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to search for a value of a variable in multiple data sets?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Is-there-a-way-to-search-for-a-value-of-a-variable-in-multiple/m-p/910592#M40758</link>
      <description>&lt;P&gt;I learned call execute in a class I took at my university.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jan 2024 12:17:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Is-there-a-way-to-search-for-a-value-of-a-variable-in-multiple/m-p/910592#M40758</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2024-01-05T12:17:48Z</dc:date>
    </item>
  </channel>
</rss>

