<?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: Subsetting in a group of values in sas in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Subsetting-in-a-group-of-values-in-sas/m-p/801061#M315233</link>
    <description>&lt;P&gt;I'm not quite understanding your question. When I look at this, you could just filter where code = `B1` to get what you need. But I'm thinking that there may be additional patterns that are not shown in your example data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Additionally, it helps us to have a reproducible example in the following format. A screenshot isn't helpful for us to resolve your issue, and we can often make mistakes trying to replicate what you have posted in a screenshot.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines delimiter = ' ';
input id date :date9. code :$2. flag cnt;
format date date9.;
datalines;
1 30NOV2021 B1 1 1
1 31OCT2021 X1 0 0
1 30SEP2021 Z1 0 0
1 31AUG2021 A1 1 1
1 31JUL2021 A1 1 2
1 30JUN2021 A1 1 3
2 30NOV2021 B1 1 1
2 31OCT2021 B1 1 2
2 30SEP2021 B1 1 3
2 31AUG2021 Z1 0 0
2 31JUL2021 A1 1 1
2 30JUN2021 A1 1 2
3 30NOV2021 B1 1 1
3 31OCT2021 B1 1 2
3 30SEP2021 Z1 0 0
3 31AUG2021 Z1 0 0
3 31JUL2021 A1 1 1
3 30JUN2021 A1 1 2
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can also use &lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;this&lt;/A&gt; to make a DATALINES statement from your actual data.&lt;/P&gt;</description>
    <pubDate>Wed, 09 Mar 2022 13:06:18 GMT</pubDate>
    <dc:creator>maguiremq</dc:creator>
    <dc:date>2022-03-09T13:06:18Z</dc:date>
    <item>
      <title>Subsetting in a group of values in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subsetting-in-a-group-of-values-in-sas/m-p/801058#M315230</link>
      <description>&lt;P&gt;Hello members,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to filter out multiple rows from a group of observation where it matches to my need. So i have a dataset where each id will have 6 observations with different codes and the observations i need has specific codes for example A1 and B1 but from these codes also i need observations which are populated after any other code from the above two. Below is the quick snapshot of the dummy data and i need all the observations highlighted in green. Please let me know if i am unable to post my question properly or more details required.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Sunboyss30_0-1646833707031.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/69280i05D171A18A6B003C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Sunboyss30_0-1646833707031.png" alt="Sunboyss30_0-1646833707031.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Mar 2022 13:48:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subsetting-in-a-group-of-values-in-sas/m-p/801058#M315230</guid>
      <dc:creator>Sunboyss30</dc:creator>
      <dc:date>2022-03-09T13:48:39Z</dc:date>
    </item>
    <item>
      <title>Re: Subsetting in a group of values in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subsetting-in-a-group-of-values-in-sas/m-p/801059#M315231</link>
      <description>i was able to create a flag and counter (cnt) for the observations but i need only the ones in green.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 09 Mar 2022 12:52:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subsetting-in-a-group-of-values-in-sas/m-p/801059#M315231</guid>
      <dc:creator>Sunboyss30</dc:creator>
      <dc:date>2022-03-09T12:52:21Z</dc:date>
    </item>
    <item>
      <title>Re: Subsetting in a group of values in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subsetting-in-a-group-of-values-in-sas/m-p/801061#M315233</link>
      <description>&lt;P&gt;I'm not quite understanding your question. When I look at this, you could just filter where code = `B1` to get what you need. But I'm thinking that there may be additional patterns that are not shown in your example data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Additionally, it helps us to have a reproducible example in the following format. A screenshot isn't helpful for us to resolve your issue, and we can often make mistakes trying to replicate what you have posted in a screenshot.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines delimiter = ' ';
input id date :date9. code :$2. flag cnt;
format date date9.;
datalines;
1 30NOV2021 B1 1 1
1 31OCT2021 X1 0 0
1 30SEP2021 Z1 0 0
1 31AUG2021 A1 1 1
1 31JUL2021 A1 1 2
1 30JUN2021 A1 1 3
2 30NOV2021 B1 1 1
2 31OCT2021 B1 1 2
2 30SEP2021 B1 1 3
2 31AUG2021 Z1 0 0
2 31JUL2021 A1 1 1
2 30JUN2021 A1 1 2
3 30NOV2021 B1 1 1
3 31OCT2021 B1 1 2
3 30SEP2021 Z1 0 0
3 31AUG2021 Z1 0 0
3 31JUL2021 A1 1 1
3 30JUN2021 A1 1 2
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can also use &lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;this&lt;/A&gt; to make a DATALINES statement from your actual data.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Mar 2022 13:06:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subsetting-in-a-group-of-values-in-sas/m-p/801061#M315233</guid>
      <dc:creator>maguiremq</dc:creator>
      <dc:date>2022-03-09T13:06:18Z</dc:date>
    </item>
    <item>
      <title>Re: Subsetting in a group of values in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subsetting-in-a-group-of-values-in-sas/m-p/801063#M315234</link>
      <description>&lt;P&gt;I do not understand the explanation given as to why your desired result is the green lines. Can you provide more detail on how the green lines are chosen? In addition, you mention A1, but none of the A1 lines are in green, can you also explain that part. Thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Mar 2022 13:24:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subsetting-in-a-group-of-values-in-sas/m-p/801063#M315234</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-03-09T13:24:02Z</dc:date>
    </item>
    <item>
      <title>Re: Subsetting in a group of values in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subsetting-in-a-group-of-values-in-sas/m-p/801070#M315237</link>
      <description>&lt;P&gt;Thankyou for your reply &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/281770"&gt;@maguiremq&lt;/a&gt;&amp;nbsp;.Yes the additional patterns can be between (A1 to A7) and (B1 to B7) and i need all of them except if they break in between for example in ID = 1 it had a different code (Z1 &amp;amp; X1) in Sep and Oct in between and i dont need the observations prior to that even if its one of the codes i am looking for. So i cant just simply filter out on 'B1' as a group can have all A1 or B1 codes and that ways i will have extra observations not required. Please see the code i have added 2 more ids to explain.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;data have;&lt;BR /&gt;infile datalines delimiter = ' ';&lt;BR /&gt;input id date :date9. code :$2. flag cnt;&lt;BR /&gt;format date date9.;&lt;BR /&gt;datalines;&lt;BR /&gt;1 30NOV2021 B1 1 1&lt;BR /&gt;1 31OCT2021 X1 0 0&lt;BR /&gt;1 30SEP2021 Z1 0 0&lt;BR /&gt;1 31AUG2021 A1 1 1&lt;BR /&gt;1 31JUL2021 A1 1 2&lt;BR /&gt;1 30JUN2021 A1 1 3&lt;BR /&gt;2 30NOV2021 B1 1 1&lt;BR /&gt;2 31OCT2021 B1 1 2&lt;BR /&gt;2 30SEP2021 B1 1 3&lt;BR /&gt;2 31AUG2021 Z1 0 0&lt;BR /&gt;2 31JUL2021 A1 1 1&lt;BR /&gt;2 30JUN2021 A1 1 2&lt;BR /&gt;3 30NOV2021 B1 1 1&lt;BR /&gt;3 31OCT2021 B1 1 2&lt;BR /&gt;3 30SEP2021 Z1 0 0&lt;BR /&gt;3 31AUG2021 Z1 0 0&lt;BR /&gt;3 31JUL2021 A1 1 1&lt;BR /&gt;3 30JUN2021 A1 1 2&lt;BR /&gt;4 30NOV2021 B1 1 1&lt;BR /&gt;4 31OCT2021 B1 1 2&lt;BR /&gt;4 30SEP2021 B1 1 3&lt;BR /&gt;4 31AUG2021 B1 1 4&lt;BR /&gt;4 31JUL2021 B1 1 5&lt;BR /&gt;4 30JUN2021 B1 1 6&lt;BR /&gt;5 30NOV2021 A3 1 1&lt;BR /&gt;5 31OCT2021 A2 1 2&lt;BR /&gt;5 30SEP2021 A1 1 3&lt;BR /&gt;5 31AUG2021 A1 1 4&lt;BR /&gt;5 31JUL2021 A1 1 5&lt;BR /&gt;5 30JUN2021 A1 1 6&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If i just filter on the required codes will give extra observations and i need only the ones highlighted.&lt;/P&gt;
&lt;TABLE width="274"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="50"&gt;id&lt;/TD&gt;
&lt;TD width="74"&gt;date&lt;/TD&gt;
&lt;TD width="50"&gt;code&lt;/TD&gt;
&lt;TD width="50"&gt;flag&lt;/TD&gt;
&lt;TD width="50"&gt;cnt&lt;/TD&gt;
&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t;/TD&gt;
&lt;TD&gt;&lt;SPAN&gt;A1&lt;/SPAN&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;SPAN&gt;1&lt;/SPAN&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;SPAN&gt;1&lt;/SPAN&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&lt;SPAN&gt;3&lt;/SPAN&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;SPAN&gt;30Jun2021&lt;/SPAN&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;SPAN&gt;A1&lt;/SPAN&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;SPAN&gt;1&lt;/SPAN&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;SPAN&gt;2&lt;/SPAN&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Wed, 09 Mar 2022 13:49:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subsetting-in-a-group-of-values-in-sas/m-p/801070#M315237</guid>
      <dc:creator>Sunboyss30</dc:creator>
      <dc:date>2022-03-09T13:49:57Z</dc:date>
    </item>
    <item>
      <title>Re: Subsetting in a group of values in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subsetting-in-a-group-of-values-in-sas/m-p/801074#M315240</link>
      <description>&lt;P&gt;Thankyou for your reply&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;. i have tried to add more explanation to the above.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Mar 2022 13:54:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subsetting-in-a-group-of-values-in-sas/m-p/801074#M315240</guid>
      <dc:creator>Sunboyss30</dc:creator>
      <dc:date>2022-03-09T13:54:22Z</dc:date>
    </item>
    <item>
      <title>Re: Subsetting in a group of values in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subsetting-in-a-group-of-values-in-sas/m-p/801075#M315241</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;... and i dont need the observations prior to that even if its one of the codes i am looking for ...&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;"Prior" in this case means chronologically? So September is prior to October? "Prior" is not being used to indicate prior row in the data set?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Mar 2022 13:59:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subsetting-in-a-group-of-values-in-sas/m-p/801075#M315241</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-03-09T13:59:00Z</dc:date>
    </item>
    <item>
      <title>Re: Subsetting in a group of values in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subsetting-in-a-group-of-values-in-sas/m-p/801076#M315242</link>
      <description>Yes in the chronologically order. Meaning if i have any code other than A1-A7 and B1-B7 in between any 6 month cycle. Then only keep the observations per group for the latest months .</description>
      <pubDate>Wed, 09 Mar 2022 14:07:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subsetting-in-a-group-of-values-in-sas/m-p/801076#M315242</guid>
      <dc:creator>Sunboyss30</dc:creator>
      <dc:date>2022-03-09T14:07:18Z</dc:date>
    </item>
    <item>
      <title>Re: Subsetting in a group of values in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subsetting-in-a-group-of-values-in-sas/m-p/801079#M315244</link>
      <description>&lt;P&gt;Okay, I see that you mentioned months in here, and that would change things drastically. Accordingly, this solution may not work if you need this sorted by month. This seems to fit your parameters, but I see it as a bit clunky. I don't really like mixing DATA steps and PROC SQL, but sometimes they work well together.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines delimiter = ' ';
input id date :date9. code :$2. flag cnt;
format date date9.;
datalines;
1 30NOV2021 B1 1 1
1 31OCT2021 X1 0 0
1 30SEP2021 Z1 0 0
1 31AUG2021 A1 1 1
1 31JUL2021 A1 1 2
1 30JUN2021 A1 1 3
2 30NOV2021 B1 1 1
2 31OCT2021 B1 1 2
2 30SEP2021 B1 1 3
2 31AUG2021 Z1 0 0
2 31JUL2021 A1 1 1
2 30JUN2021 A1 1 2
3 30NOV2021 B1 1 1
3 31OCT2021 B1 1 2
3 30SEP2021 Z1 0 0
3 31AUG2021 Z1 0 0
3 31JUL2021 A1 1 1
3 30JUN2021 A1 1 2
4 30NOV2021 B1 1 1
4 31OCT2021 B1 1 2
4 30SEP2021 B1 1 3
4 31AUG2021 B1 1 4
4 31JUL2021 B1 1 5
4 30JUN2021 B1 1 6
5 30NOV2021 A3 1 1
5 31OCT2021 A2 1 2
5 30SEP2021 A1 1 3
5 31AUG2021 A1 1 4
5 31JUL2021 A1 1 5
5 30JUN2021 A1 1 6
;
run;

data 	have_subset;
	set have (keep = id date code);
	by 	id;
		if first.id then seq = 1;
		if id = lag(id) and code ~= lag(code) then seq + 1;
		if code in ('A1', 'B1') then flag = 1;
			else flag = 0;
run;

proc sql;
	create table 	want as
		select
					id,
					date,
					code
		from
					have_subset
		where
					flag = 1
		group by
					id
		having
					seq = min(seq);
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="maguiremq_0-1646835637213.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/69281i78BCD692C865BB17/image-size/medium?v=v2&amp;amp;px=400" role="button" title="maguiremq_0-1646835637213.png" alt="maguiremq_0-1646835637213.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Mar 2022 14:21:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subsetting-in-a-group-of-values-in-sas/m-p/801079#M315244</guid>
      <dc:creator>maguiremq</dc:creator>
      <dc:date>2022-03-09T14:21:05Z</dc:date>
    </item>
    <item>
      <title>Re: Subsetting in a group of values in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subsetting-in-a-group-of-values-in-sas/m-p/801094#M315254</link>
      <description>&lt;P&gt;Thankyou&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/281770"&gt;@maguiremq&lt;/a&gt;&amp;nbsp;its almost there and i am getting the results as expected with one last thing that in your answer if the code in ('A1','B1') but here i am looking for all the codes between A1-A7 and B1-B7. Since the code is doing seq increment on the basis of previous code not matching. So if i replace the code with below snippet i am only getting one record for the id = 5 whereas it should have all 6 records since the code for that id has A1-A3 which can be upto A7. Apologies if I haven't explained it earlier.&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;if code in ('A1','A2','A3','A4','A5','A6','A7','B1','B2','B3','B4','B5','B6','B7') 
then flag = 1;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Mar 2022 15:25:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subsetting-in-a-group-of-values-in-sas/m-p/801094#M315254</guid>
      <dc:creator>Sunboyss30</dc:creator>
      <dc:date>2022-03-09T15:25:43Z</dc:date>
    </item>
    <item>
      <title>Re: Subsetting in a group of values in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subsetting-in-a-group-of-values-in-sas/m-p/801145#M315274</link>
      <description>&lt;P&gt;Do you want something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  by id;

  if first.id then out = 1; retain out; drop out;
  if code in ('Z1' 'X1') then out = 0;
  if out then output;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Wed, 09 Mar 2022 17:09:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subsetting-in-a-group-of-values-in-sas/m-p/801145#M315274</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2022-03-09T17:09:58Z</dc:date>
    </item>
    <item>
      <title>Re: Subsetting in a group of values in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subsetting-in-a-group-of-values-in-sas/m-p/801256#M315330</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35763"&gt;@yabwon&lt;/a&gt;&amp;nbsp;Thankyou for your reply. Yes its perfect and that's what i was looking for. Really appreciate.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Mar 2022 07:57:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subsetting-in-a-group-of-values-in-sas/m-p/801256#M315330</guid>
      <dc:creator>Sunboyss30</dc:creator>
      <dc:date>2022-03-10T07:57:04Z</dc:date>
    </item>
  </channel>
</rss>

