<?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 Count and subset from a dataset based on combinations of values of variables in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Count-and-subset-from-a-dataset-based-on-combinations-of-values/m-p/945313#M42465</link>
    <description>&lt;P&gt;Hi guys,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;suppose to have the following dataset:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data DB;
  input ID :$20. Admission :date09. Discharge :date09. Code1 Code2 Code3;
  format Admission date9. Discharge date9.;
cards;
0001  13JAN2017 25JAN2017  345   6    8
0001  22FEB2018 03MAR2018   5   21   64
0001  30JAN2019 04MAR2019  V45   6   43
0002  01DEC2016 14DEC2016  56    0   998
0002  01DEC2016 14DEC2016  54   V321 65
0002  25DEC2017 02JAN2018  543  987  098
0002  06JAN2018 09JAN2018  21   468  765
;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and a list of codes in combination as follows:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) 345, 8&lt;/P&gt;
&lt;P&gt;2) 543, 098&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a way to count how many times the combinations occur in DB (looking at variables Code1, Code2, Code3), and subset the records (rows) where they appear and save into two different datasets according to the combinations? In other words two sub-datasets will be generated: one for combination 1) and the other for combination 2).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advance&lt;/P&gt;</description>
    <pubDate>Thu, 26 Sep 2024 11:43:27 GMT</pubDate>
    <dc:creator>NewUsrStat</dc:creator>
    <dc:date>2024-09-26T11:43:27Z</dc:date>
    <item>
      <title>Count and subset from a dataset based on combinations of values of variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Count-and-subset-from-a-dataset-based-on-combinations-of-values/m-p/945313#M42465</link>
      <description>&lt;P&gt;Hi guys,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;suppose to have the following dataset:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data DB;
  input ID :$20. Admission :date09. Discharge :date09. Code1 Code2 Code3;
  format Admission date9. Discharge date9.;
cards;
0001  13JAN2017 25JAN2017  345   6    8
0001  22FEB2018 03MAR2018   5   21   64
0001  30JAN2019 04MAR2019  V45   6   43
0002  01DEC2016 14DEC2016  56    0   998
0002  01DEC2016 14DEC2016  54   V321 65
0002  25DEC2017 02JAN2018  543  987  098
0002  06JAN2018 09JAN2018  21   468  765
;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and a list of codes in combination as follows:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) 345, 8&lt;/P&gt;
&lt;P&gt;2) 543, 098&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a way to count how many times the combinations occur in DB (looking at variables Code1, Code2, Code3), and subset the records (rows) where they appear and save into two different datasets according to the combinations? In other words two sub-datasets will be generated: one for combination 1) and the other for combination 2).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advance&lt;/P&gt;</description>
      <pubDate>Thu, 26 Sep 2024 11:43:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Count-and-subset-from-a-dataset-based-on-combinations-of-values/m-p/945313#M42465</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2024-09-26T11:43:27Z</dc:date>
    </item>
    <item>
      <title>Re: Count and subset from a dataset based on combinations of values of variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Count-and-subset-from-a-dataset-based-on-combinations-of-values/m-p/945314#M42466</link>
      <description>&lt;P&gt;Partial code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want1 want2;
    set db;
    if whichn(345,of code1-code3)&amp;gt;0 and whichn(8,of code1-code3)&amp;gt;0 then output want1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See if you can program the rest from the above fragment. (Question: it seems as if code1-code3 is really character variables, but you have programmed them as numeric, is that right?)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Advice: create flag variables FLAG1 and FLAG2 and leave everything in one data set. Use this one data set instead of two separate data sets. If you have FLAG1 and FLAG2, then PROC FREQ computes the counts easily.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Sep 2024 12:04:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Count-and-subset-from-a-dataset-based-on-combinations-of-values/m-p/945314#M42466</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-09-26T12:04:10Z</dc:date>
    </item>
    <item>
      <title>Re: Count and subset from a dataset based on combinations of values of variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Count-and-subset-from-a-dataset-based-on-combinations-of-values/m-p/945326#M42467</link>
      <description>&lt;P&gt;I would suggest keeping the data in one dataset.&lt;/P&gt;
&lt;P&gt;Assuming you want to check for both codes on the same observation then you could code it this way.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data DB;
  length ID $20 Admission Discharge 8  Code1-Code3 $5 ;
  input id -- code3;
  format Admission Discharge date9.;
  informat Admission Discharge date.;
cards;
0001  13JAN2017 25JAN2017  345   6    8
0001  22FEB2018 03MAR2018   5   21   64
0001  30JAN2019 04MAR2019  V45   6   43
0002  01DEC2016 14DEC2016  56    0   998
0002  01DEC2016 14DEC2016  54   V321 65
0002  25DEC2017 02JAN2018  543  987  098
0002  06JAN2018 09JAN2018  21   468  765
;

data want;
  set db ;
  array dx code1-code3;
  flag1= ('345' in dx) and ('8' in dx);
  flag2= ('543' in dx) and ('098' in dx);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1727358109187.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/100689i14A99C4DB3AC1094/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1727358109187.png" alt="Tom_0-1727358109187.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Sep 2024 13:41:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Count-and-subset-from-a-dataset-based-on-combinations-of-values/m-p/945326#M42467</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-09-26T13:41:56Z</dc:date>
    </item>
  </channel>
</rss>

