<?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: Count unique pipe delimited codes by group in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Count-unique-pipe-delimited-codes-by-group/m-p/64715#M18390</link>
    <description>Using a DATA step, read up the record using just an INPUT ;  statement (no variables specified), then parse _INFILE_, first to get your GROUP, and then iterate with SCAN through each CODES that is present and do an OUTPUT for each.  Then use PROC SORT NODUPKEY with BY on GROUP CODES, and then PROC SUMMARY to get your _FREQ_ count with BY GROUP.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;BR /&gt;
&lt;BR /&gt;
Suggested Google advanced search argument, this topic / post:&lt;BR /&gt;
&lt;BR /&gt;
data step programming introduction site:sas.com

Message was edited by: sbb</description>
    <pubDate>Mon, 16 Aug 2010 22:15:42 GMT</pubDate>
    <dc:creator>sbb</dc:creator>
    <dc:date>2010-08-16T22:15:42Z</dc:date>
    <item>
      <title>Count unique pipe delimited codes by group</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Count-unique-pipe-delimited-codes-by-group/m-p/64714#M18389</link>
      <description>I am new to SAS and have run into a problem that I cannot solve. I am trying to count the number of unique codes in a group. Each group consist of multiple rows and the codes are pipe delimited in each cell. A sample of my dataset looks like this:&lt;BR /&gt;
&lt;BR /&gt;
GROUP CODES&lt;BR /&gt;
1 |231|322|414|&lt;BR /&gt;
1 |231|322|2 |231|&lt;BR /&gt;
2 |231|114|&lt;BR /&gt;
2&lt;BR /&gt;
3&lt;BR /&gt;
3&lt;BR /&gt;
&lt;BR /&gt;
So in GROUP 1 there are 3 unique codes (231, 322, and 414) and in GROUP 2 there are 2 unique codes (231 and 114) There are 0 codes in GROUP 3. Can anyone tell me how to get SAS to give me an output dataset like this:&lt;BR /&gt;
&lt;BR /&gt;
Group Count&lt;BR /&gt;
1 3&lt;BR /&gt;
2 2&lt;BR /&gt;
3 0&lt;BR /&gt;
&lt;BR /&gt;
Thanks in advance.&lt;BR /&gt;
Chris</description>
      <pubDate>Mon, 16 Aug 2010 20:38:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Count-unique-pipe-delimited-codes-by-group/m-p/64714#M18389</guid>
      <dc:creator>cte1</dc:creator>
      <dc:date>2010-08-16T20:38:18Z</dc:date>
    </item>
    <item>
      <title>Re: Count unique pipe delimited codes by group</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Count-unique-pipe-delimited-codes-by-group/m-p/64715#M18390</link>
      <description>Using a DATA step, read up the record using just an INPUT ;  statement (no variables specified), then parse _INFILE_, first to get your GROUP, and then iterate with SCAN through each CODES that is present and do an OUTPUT for each.  Then use PROC SORT NODUPKEY with BY on GROUP CODES, and then PROC SUMMARY to get your _FREQ_ count with BY GROUP.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;BR /&gt;
&lt;BR /&gt;
Suggested Google advanced search argument, this topic / post:&lt;BR /&gt;
&lt;BR /&gt;
data step programming introduction site:sas.com

Message was edited by: sbb</description>
      <pubDate>Mon, 16 Aug 2010 22:15:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Count-unique-pipe-delimited-codes-by-group/m-p/64715#M18390</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-08-16T22:15:42Z</dc:date>
    </item>
    <item>
      <title>Re: Count unique pipe delimited codes by group</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Count-unique-pipe-delimited-codes-by-group/m-p/64716#M18391</link>
      <description>normalise it with proc transpose, so it is just&lt;BR /&gt;
group, code&lt;BR /&gt;
then &lt;BR /&gt;
proc summary (or means or freq)&lt;BR /&gt;
have a look in the online doc</description>
      <pubDate>Mon, 16 Aug 2010 22:16:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Count-unique-pipe-delimited-codes-by-group/m-p/64716#M18391</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2010-08-16T22:16:27Z</dc:date>
    </item>
    <item>
      <title>Re: Count unique pipe delimited codes by group</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Count-unique-pipe-delimited-codes-by-group/m-p/64717#M18392</link>
      <description>Since you are new to SAS, here is one coded solution to your problem. &lt;BR /&gt;
&lt;BR /&gt;
data sample;&lt;BR /&gt;
length group 3 code 3;&lt;BR /&gt;
infile cards dlm='|' truncover;&lt;BR /&gt;
input &lt;BR /&gt;
   group&lt;BR /&gt;
   code @;&lt;BR /&gt;
output;&lt;BR /&gt;
do while ( not missing( code ));&lt;BR /&gt;
   input code @;&lt;BR /&gt;
   if not missing( code ) then output;&lt;BR /&gt;
end;&lt;BR /&gt;
cards;&lt;BR /&gt;
1 |231|322|414|&lt;BR /&gt;
1 |231|322|2 |231|&lt;BR /&gt;
2 |231|114|&lt;BR /&gt;
2&lt;BR /&gt;
3&lt;BR /&gt;
3&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sort nodupkey data=sample; * nodup option would also work since all variables are in by-group;&lt;BR /&gt;
by group code;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
* Summary #1: Proc Means;&lt;BR /&gt;
proc summary data=sample nway;&lt;BR /&gt;
class group;&lt;BR /&gt;
var code;&lt;BR /&gt;
output out=summary (drop=_:) n=count;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
* Summary #2: Proc SQL;&lt;BR /&gt;
proc sql;&lt;BR /&gt;
create table summary2 as&lt;BR /&gt;
select&lt;BR /&gt;
   group,&lt;BR /&gt;
   sum( case&lt;BR /&gt;
      when not missing( code ) then 1&lt;BR /&gt;
      else 0&lt;BR /&gt;
   end ) as count&lt;BR /&gt;
from&lt;BR /&gt;
   sample&lt;BR /&gt;
group by 1&lt;BR /&gt;
;&lt;BR /&gt;
quit;</description>
      <pubDate>Fri, 20 Aug 2010 21:31:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Count-unique-pipe-delimited-codes-by-group/m-p/64717#M18392</guid>
      <dc:creator>FloydNevseta</dc:creator>
      <dc:date>2010-08-20T21:31:03Z</dc:date>
    </item>
  </channel>
</rss>

