<?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: Pull observations within a variable that contains at least one of a list of values in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Pull-observations-within-a-variable-that-contains-at-least-one/m-p/611958#M18548</link>
    <description>&lt;P&gt;Do you want the first 5&amp;nbsp; of 'aaa' OR 'bbb'?&amp;nbsp; Or do you want the first 5 'aaa' and the first 5 'bbb'?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it's the earlier then&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc print data = dataset (obs=5);
 where var in: ("aaa", "bbb");
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;As &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;mentioned the in : assumes you are looking a values the start with 'aaa' or 'bbb'.&amp;nbsp; Note that the "obs=5" honors the where filter.&amp;nbsp; I.e. you will get 5 qualifying records, not the qualifying subset of the first 5 records.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But if it's the latter, then:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data need / view=need;
  set dataset (where=(var=:'aaa') obs=5)
      dataset (where=(var=:'bbb') obs=5);
  by id;
run;
proc print data=need;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I put in the "by id;" to illustrate what you can do if the data are already sorted by ID and you want the 10 records printed out in original order.&amp;nbsp; If you don't use the BY statement, then it will print 5 'aaa' records, then 5 'bbb' records.&lt;/P&gt;</description>
    <pubDate>Mon, 16 Dec 2019 06:07:28 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2019-12-16T06:07:28Z</dc:date>
    <item>
      <title>Pull observations within a variable that contains at least one of a list of values</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Pull-observations-within-a-variable-that-contains-at-least-one/m-p/611921#M18545</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset where there are a bunch of character values for a variable (var). I want to print all observations that contain one of the values from a list of values for var.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried this code, but I think you can only put one value if you use the index function (i.e. can only list "abc" or "bbb", not both). Is there a function like the index function but where you can list multiple values?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc print data = dataset; where index (var, "abc", "bbb"); run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example dataset:&lt;/P&gt;&lt;P&gt;var&lt;/P&gt;&lt;P&gt;abc ab&lt;/P&gt;&lt;P&gt;abc bb&lt;/P&gt;&lt;P&gt;abc da&lt;/P&gt;&lt;P&gt;abc rr&lt;/P&gt;&lt;P&gt;bbb ab&lt;/P&gt;&lt;P&gt;ccc&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(I only want to print first 5 observations)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Thx!&lt;/P&gt;</description>
      <pubDate>Sun, 15 Dec 2019 21:29:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Pull-observations-within-a-variable-that-contains-at-least-one/m-p/611921#M18545</guid>
      <dc:creator>KPCklebspn</dc:creator>
      <dc:date>2019-12-15T21:29:33Z</dc:date>
    </item>
    <item>
      <title>Re: Pull observations within a variable that contains at least one of a list of values</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Pull-observations-within-a-variable-that-contains-at-least-one/m-p/611922#M18546</link>
      <description>&lt;P&gt;Here's an option:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Tom&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Want;
	length TestWord $50;
	set Have;
	WordFound = 0;

	do WordCount = 1 to countw(Var);
		TestWord = scan(Var, WordCount);

		if TestWord in("abc", "bbb") then
			WordFound = 1;
	end;

	if WordFound then
		output;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 15 Dec 2019 21:41:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Pull-observations-within-a-variable-that-contains-at-least-one/m-p/611922#M18546</guid>
      <dc:creator>TomKari</dc:creator>
      <dc:date>2019-12-15T21:41:42Z</dc:date>
    </item>
    <item>
      <title>Re: Pull observations within a variable that contains at least one of a list of values</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Pull-observations-within-a-variable-that-contains-at-least-one/m-p/611925#M18547</link>
      <description>&lt;P&gt;In the examples you listed, the key word appears at the beginning of VAR.&amp;nbsp; If that pattern holds true you can use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;where var in : ('abc', 'bbb');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The colon will limit the number of characters used for making a comparison.&lt;/P&gt;</description>
      <pubDate>Sun, 15 Dec 2019 23:04:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Pull-observations-within-a-variable-that-contains-at-least-one/m-p/611925#M18547</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-12-15T23:04:22Z</dc:date>
    </item>
    <item>
      <title>Re: Pull observations within a variable that contains at least one of a list of values</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Pull-observations-within-a-variable-that-contains-at-least-one/m-p/611958#M18548</link>
      <description>&lt;P&gt;Do you want the first 5&amp;nbsp; of 'aaa' OR 'bbb'?&amp;nbsp; Or do you want the first 5 'aaa' and the first 5 'bbb'?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it's the earlier then&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc print data = dataset (obs=5);
 where var in: ("aaa", "bbb");
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;As &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;mentioned the in : assumes you are looking a values the start with 'aaa' or 'bbb'.&amp;nbsp; Note that the "obs=5" honors the where filter.&amp;nbsp; I.e. you will get 5 qualifying records, not the qualifying subset of the first 5 records.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But if it's the latter, then:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data need / view=need;
  set dataset (where=(var=:'aaa') obs=5)
      dataset (where=(var=:'bbb') obs=5);
  by id;
run;
proc print data=need;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I put in the "by id;" to illustrate what you can do if the data are already sorted by ID and you want the 10 records printed out in original order.&amp;nbsp; If you don't use the BY statement, then it will print 5 'aaa' records, then 5 'bbb' records.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Dec 2019 06:07:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Pull-observations-within-a-variable-that-contains-at-least-one/m-p/611958#M18548</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2019-12-16T06:07:28Z</dc:date>
    </item>
    <item>
      <title>Re: Pull observations within a variable that contains at least one of a list of values</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Pull-observations-within-a-variable-that-contains-at-least-one/m-p/612127#M18550</link>
      <description>PRXMATCH can test for a match against multiple strings.  As was mentioned already, using the IN: construct would be easier (and probably faster) if the qualifying string is always at the beginning.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 16 Dec 2019 18:21:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Pull-observations-within-a-variable-that-contains-at-least-one/m-p/612127#M18550</guid>
      <dc:creator>JackHamilton</dc:creator>
      <dc:date>2019-12-16T18:21:49Z</dc:date>
    </item>
  </channel>
</rss>

