<?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 get the frequency of options by group in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-frequency-of-options-by-group/m-p/796676#M255674</link>
    <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a data set with multiple options and I need to get the frequency count of each option (the total number of options A, B, C, etc. by ID).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data example;&lt;/P&gt;&lt;P&gt;input ID option1 $ option2 $ option3 $;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;Item1 A D F&amp;nbsp;&lt;/P&gt;&lt;P&gt;Item1 A C E&lt;/P&gt;&lt;P&gt;Item1 B D F&lt;/P&gt;&lt;P&gt;Item1 C D E&lt;/P&gt;&lt;P&gt;Item2 A B D&lt;/P&gt;&lt;P&gt;Item2 A C F&lt;/P&gt;&lt;P&gt;Item2 C D F&lt;/P&gt;&lt;P&gt;Item3 A E&lt;/P&gt;&lt;P&gt;Item3 B D&lt;/P&gt;&lt;P&gt;Item3 C E&lt;/P&gt;&lt;P&gt;Item3 D E&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;ID A&amp;nbsp; B&amp;nbsp; C&amp;nbsp; D&amp;nbsp; E&amp;nbsp; F ;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;Item1 2 1 2 3 2 2&lt;/P&gt;&lt;P&gt;Item2 2 1 2 2 0 2&lt;/P&gt;&lt;P&gt;Item3 1 1 1 2 3 .&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The data I would like can be a table like using proc sql. I can't get the proc sql to work. Thank you in advance!&lt;/P&gt;</description>
    <pubDate>Wed, 16 Feb 2022 19:31:02 GMT</pubDate>
    <dc:creator>lapetitemaman</dc:creator>
    <dc:date>2022-02-16T19:31:02Z</dc:date>
    <item>
      <title>How to get the frequency of options by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-frequency-of-options-by-group/m-p/796676#M255674</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a data set with multiple options and I need to get the frequency count of each option (the total number of options A, B, C, etc. by ID).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data example;&lt;/P&gt;&lt;P&gt;input ID option1 $ option2 $ option3 $;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;Item1 A D F&amp;nbsp;&lt;/P&gt;&lt;P&gt;Item1 A C E&lt;/P&gt;&lt;P&gt;Item1 B D F&lt;/P&gt;&lt;P&gt;Item1 C D E&lt;/P&gt;&lt;P&gt;Item2 A B D&lt;/P&gt;&lt;P&gt;Item2 A C F&lt;/P&gt;&lt;P&gt;Item2 C D F&lt;/P&gt;&lt;P&gt;Item3 A E&lt;/P&gt;&lt;P&gt;Item3 B D&lt;/P&gt;&lt;P&gt;Item3 C E&lt;/P&gt;&lt;P&gt;Item3 D E&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;ID A&amp;nbsp; B&amp;nbsp; C&amp;nbsp; D&amp;nbsp; E&amp;nbsp; F ;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;Item1 2 1 2 3 2 2&lt;/P&gt;&lt;P&gt;Item2 2 1 2 2 0 2&lt;/P&gt;&lt;P&gt;Item3 1 1 1 2 3 .&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The data I would like can be a table like using proc sql. I can't get the proc sql to work. Thank you in advance!&lt;/P&gt;</description>
      <pubDate>Wed, 16 Feb 2022 19:31:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-frequency-of-options-by-group/m-p/796676#M255674</guid>
      <dc:creator>lapetitemaman</dc:creator>
      <dc:date>2022-02-16T19:31:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the frequency of options by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-frequency-of-options-by-group/m-p/796695#M255680</link>
      <description>&lt;P&gt;First, test your data step before posting. It has errors because the values of ID are not numeric.&lt;/P&gt;
&lt;P&gt;Second, paste code in either a text box or code box, opened on the forum with the "running man" or &amp;lt;/&amp;gt; icons.&lt;/P&gt;
&lt;P&gt;The message windows will reformat text and position dependent code often will not run correctly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One way:&lt;/P&gt;
&lt;PRE&gt;data example;
infile datalines truncover;
input ID $ option1 $ option2 $ option3 $;
datalines;
Item1 A D F 
Item1 A C E
Item1 B D F
Item1 C D E
Item2 A B D
Item2 A C F
Item2 C D F
Item3 A E
Item3 B D
Item3 C E
Item3 D E
;

data helper;
   set example;
   array o (*) option: ;
   do i= 1 to dim (o);
      opt= o[i];
      if not missing(opt) then output;
   end;
   keep id opt;
run;

proc freq data=helper noprint;
   tables id*opt/ out=counted (drop=percent);
run;

proc transpose data=counted out=want (drop=_name_ _label_);
   by id;
   id opt;
   var count;
run;
&lt;/PRE&gt;
&lt;P&gt;This is to create a data set. Getting a count for something that doesn't occur would be another step if you really want a 0.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you just wanted a report for people to read perhaps:&lt;/P&gt;
&lt;PRE&gt;proc tabulate data=helper;
   class id opt;
   table id,
         opt=''  * n=" "
         /misstext='0'
   ;
run;

&lt;/PRE&gt;</description>
      <pubDate>Wed, 16 Feb 2022 20:22:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-frequency-of-options-by-group/m-p/796695#M255680</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-02-16T20:22:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the frequency of options by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-frequency-of-options-by-group/m-p/796720#M255681</link>
      <description>Thank you and I will be more careful in the future.</description>
      <pubDate>Wed, 16 Feb 2022 21:58:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-frequency-of-options-by-group/m-p/796720#M255681</guid>
      <dc:creator>lapetitemaman</dc:creator>
      <dc:date>2022-02-16T21:58:08Z</dc:date>
    </item>
  </channel>
</rss>

