<?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 How to extract id number based on another variable? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-id-number-based-on-another-variable/m-p/888167#M350919</link>
    <description>&lt;P&gt;Hi!&lt;/P&gt;
&lt;P&gt;I have a dataset like the one below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I wish to extra the id where the variable "atc" only has "A10A".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, in this example, I would extract id=282 and id=299.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does anyone know how to achieve this in SAS? Thank you!!&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 96pt;" border="0" width="128" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD width="64" height="19" style="height: 14.4pt; width: 48pt;"&gt;id&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;atc&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" class="xl63" style="height: 14.4pt;"&gt;233&lt;/TD&gt;
&lt;TD class="xl64"&gt;A10A&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" class="xl63" style="height: 14.4pt;"&gt;233&lt;/TD&gt;
&lt;TD class="xl64"&gt;A10A&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" class="xl63" style="height: 14.4pt;"&gt;233&lt;/TD&gt;
&lt;TD class="xl63"&gt;C05&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" class="xl63" style="height: 14.4pt;"&gt;233&lt;/TD&gt;
&lt;TD class="xl63"&gt;V90A&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" class="xl63" style="height: 14.4pt;"&gt;233&lt;/TD&gt;
&lt;TD class="xl63"&gt;V90A&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" class="xl63" style="height: 14.4pt;"&gt;233&lt;/TD&gt;
&lt;TD class="xl63"&gt;V90A&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" class="xl63" style="height: 14.4pt;"&gt;233&lt;/TD&gt;
&lt;TD class="xl63"&gt;V90A&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" class="xl63" style="height: 14.4pt;"&gt;233&lt;/TD&gt;
&lt;TD class="xl63"&gt;G560&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" class="xl63" style="height: 14.4pt;"&gt;233&lt;/TD&gt;
&lt;TD class="xl63"&gt;G561&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" class="xl63" style="height: 14.4pt;"&gt;233&lt;/TD&gt;
&lt;TD class="xl63"&gt;G562&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" style="height: 14.4pt;"&gt;282&lt;/TD&gt;
&lt;TD class="xl65"&gt;A10A&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" style="height: 14.4pt;"&gt;282&lt;/TD&gt;
&lt;TD class="xl65"&gt;A10A&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" style="height: 14.4pt;"&gt;282&lt;/TD&gt;
&lt;TD class="xl65"&gt;A10A&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" style="height: 14.4pt;"&gt;282&lt;/TD&gt;
&lt;TD class="xl65"&gt;A10A&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" class="xl63" style="height: 14.4pt;"&gt;299&lt;/TD&gt;
&lt;TD class="xl64"&gt;A10A&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
    <pubDate>Mon, 07 Aug 2023 16:20:54 GMT</pubDate>
    <dc:creator>zihdonv19</dc:creator>
    <dc:date>2023-08-07T16:20:54Z</dc:date>
    <item>
      <title>How to extract id number based on another variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-id-number-based-on-another-variable/m-p/888167#M350919</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;
&lt;P&gt;I have a dataset like the one below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I wish to extra the id where the variable "atc" only has "A10A".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, in this example, I would extract id=282 and id=299.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does anyone know how to achieve this in SAS? Thank you!!&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 96pt;" border="0" width="128" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD width="64" height="19" style="height: 14.4pt; width: 48pt;"&gt;id&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;atc&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" class="xl63" style="height: 14.4pt;"&gt;233&lt;/TD&gt;
&lt;TD class="xl64"&gt;A10A&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" class="xl63" style="height: 14.4pt;"&gt;233&lt;/TD&gt;
&lt;TD class="xl64"&gt;A10A&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" class="xl63" style="height: 14.4pt;"&gt;233&lt;/TD&gt;
&lt;TD class="xl63"&gt;C05&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" class="xl63" style="height: 14.4pt;"&gt;233&lt;/TD&gt;
&lt;TD class="xl63"&gt;V90A&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" class="xl63" style="height: 14.4pt;"&gt;233&lt;/TD&gt;
&lt;TD class="xl63"&gt;V90A&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" class="xl63" style="height: 14.4pt;"&gt;233&lt;/TD&gt;
&lt;TD class="xl63"&gt;V90A&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" class="xl63" style="height: 14.4pt;"&gt;233&lt;/TD&gt;
&lt;TD class="xl63"&gt;V90A&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" class="xl63" style="height: 14.4pt;"&gt;233&lt;/TD&gt;
&lt;TD class="xl63"&gt;G560&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" class="xl63" style="height: 14.4pt;"&gt;233&lt;/TD&gt;
&lt;TD class="xl63"&gt;G561&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" class="xl63" style="height: 14.4pt;"&gt;233&lt;/TD&gt;
&lt;TD class="xl63"&gt;G562&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" style="height: 14.4pt;"&gt;282&lt;/TD&gt;
&lt;TD class="xl65"&gt;A10A&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" style="height: 14.4pt;"&gt;282&lt;/TD&gt;
&lt;TD class="xl65"&gt;A10A&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" style="height: 14.4pt;"&gt;282&lt;/TD&gt;
&lt;TD class="xl65"&gt;A10A&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" style="height: 14.4pt;"&gt;282&lt;/TD&gt;
&lt;TD class="xl65"&gt;A10A&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" class="xl63" style="height: 14.4pt;"&gt;299&lt;/TD&gt;
&lt;TD class="xl64"&gt;A10A&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Mon, 07 Aug 2023 16:20:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-id-number-based-on-another-variable/m-p/888167#M350919</guid>
      <dc:creator>zihdonv19</dc:creator>
      <dc:date>2023-08-07T16:20:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract id number based on another variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-id-number-based-on-another-variable/m-p/888171#M350920</link>
      <description>&lt;P&gt;It would be extremely helpful, in this problem and all future problems, if you SHOW US the desired output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since you haven't done that, please do so now. Please also explain why rows 1 and 2, where &lt;FONT face="courier new,courier"&gt;atc=&lt;/FONT&gt;&lt;SPAN&gt;&lt;FONT face="courier new,courier"&gt;"A10A"&lt;/FONT&gt; are not in the output.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Aug 2023 16:28:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-id-number-based-on-another-variable/m-p/888171#M350920</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-08-07T16:28:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract id number based on another variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-id-number-based-on-another-variable/m-p/888174#M350922</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for your reply.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The output I'd like to have is:&lt;/P&gt;
&lt;TABLE border="0" width="63px" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="62.2px" height="30px" class="lia-align-left"&gt;id&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="62.2px" height="30px" align="right" class="xl63 lia-align-left"&gt;282&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="62.2px" class="lia-align-left"&gt;299&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Rows 1 and 2 should not be in the output, because the atc value for id "233" is not restricted to "A10A". For example, id 233 also has atc value of "C05", "V90A" etc.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Aug 2023 16:36:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-id-number-based-on-another-variable/m-p/888174#M350922</guid>
      <dc:creator>zihdonv19</dc:creator>
      <dc:date>2023-08-07T16:36:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract id number based on another variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-id-number-based-on-another-variable/m-p/888201#M350936</link>
      <description>&lt;P&gt;Your data seems sorted, so let's use that to our advantage.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  by id ;
  if first.id then other=0;
  retain other;
  if atc ne "A10A" then other=1;
  if last.id and not other;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 07 Aug 2023 18:33:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-id-number-based-on-another-variable/m-p/888201#M350936</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-08-07T18:33:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract id number based on another variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-id-number-based-on-another-variable/m-p/888220#M350944</link>
      <description>&lt;P&gt;Thanks for you reply Tom. Your solution works!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;May I further ask does "if last.lopnr and not other" always do the same as "if last.lopnr and other=0"?&lt;/P&gt;</description>
      <pubDate>Mon, 07 Aug 2023 20:08:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-id-number-based-on-another-variable/m-p/888220#M350944</guid>
      <dc:creator>zihdonv19</dc:creator>
      <dc:date>2023-08-07T20:08:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract id number based on another variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-id-number-based-on-another-variable/m-p/888255#M350965</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/332712"&gt;@zihdonv19&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks for you reply Tom. Your solution works!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;May I further ask does "if last.lopnr and not other" always do the same as "if last.lopnr and other=0"?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;In this case yes.&amp;nbsp; But in the general case it is more like&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if last.lopnr and (other=0 or missing(other));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;SAS will evaluate a zero or missing value as FALSE and any other value as TRUE.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Aug 2023 23:25:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-id-number-based-on-another-variable/m-p/888255#M350965</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-08-07T23:25:11Z</dc:date>
    </item>
  </channel>
</rss>

