<?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: counting data  across column in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/counting-data-across-column/m-p/921251#M362792</link>
    <description>&lt;P&gt;The following code will set variable&amp;nbsp;&lt;CODE class=" language-sas"&gt;MultiForm&lt;/CODE&gt;&amp;nbsp;to 1 if for an ID more than one Form variable got a value of 1.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input id$ 1-3 FormA FormB FormC;
  infile datalines;
  datalines;
101 1 . . 
101 1 0 . 
102 1 0 . 
102 . 1 . 
103 . . 0 
103 . . 1 
104 1 0 . 
104 . . 1
105 . 1 . 
;
run;

proc sql;
/*  create table want as*/
  select i.*,sum(FormA,FormB,FormC)&amp;gt;1 as MultiForm
  from
  (
    select 
      id,
      max(FormA) as FormA,
      max(FormB) as FormB,
      max(FormC) as FormC
    from have
    group by id
  ) i
  ;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1711002653982.png" style="width: 323px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/94830iD43FC3CBF42A5455/image-dimensions/323x168?v=v2" width="323" height="168" role="button" title="Patrick_0-1711002653982.png" alt="Patrick_0-1711002653982.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 21 Mar 2024 06:31:08 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2024-03-21T06:31:08Z</dc:date>
    <item>
      <title>counting data  across column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/counting-data-across-column/m-p/921144#M362752</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;Hope someone can help me out. I have a dataset where someone can complete 2 or 3 forms (e.g., form A, form B &amp;amp; form C).&lt;BR /&gt;I want a count of someone in Form A only, Form B only and Form C only and those who filled more than 1 form (mult_form). If they complete form A and form B, they should be counted as mult_form. For example, ID 102 &amp;amp; 104 to be counted as multi_form. Here is my dummy data.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data dummy;&lt;BR /&gt;input id$ 1-3 FormA FormB FormC ;&lt;BR /&gt;infile datalines ;&lt;BR /&gt;datalines;&lt;BR /&gt;101 1 0 . &lt;BR /&gt;101 . 0 . &lt;BR /&gt;102 1 0 . &lt;BR /&gt;102 . 1 . &lt;BR /&gt;103 . . 0 &lt;BR /&gt;103 . . 1 &lt;BR /&gt;104 1 0 . &lt;BR /&gt;104 . . 1&lt;BR /&gt;105 . 1 . &lt;BR /&gt;;&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2024 19:54:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/counting-data-across-column/m-p/921144#M362752</guid>
      <dc:creator>CathyVI</dc:creator>
      <dc:date>2024-03-20T19:54:57Z</dc:date>
    </item>
    <item>
      <title>Re: counting data  across column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/counting-data-across-column/m-p/921147#M362754</link>
      <description>&lt;P&gt;I am confused that you even mention 25 or 45 as don't see anything actually related to those. Please use VARIABLE names and shown values to discuss rules. Otherwise we have to interpret (translate: make a lot of guesses) what we think you mean. For example, I do not understand what "Form A only" means. You show variables with some of that text in the name but do not really tell use how to identify a "Form A Only" record, id, group or what have.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And please provide an example of two of pointing which variables, values on which rows are used to satisfy some of these criteria.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can't tell what you are starting with. Or really what the result should look like. Especially since none of the values of FormType are "Form C" but you show results in "FormC30_plus".&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2024 17:25:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/counting-data-across-column/m-p/921147#M362754</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-03-20T17:25:43Z</dc:date>
    </item>
    <item>
      <title>Re: counting data  across column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/counting-data-across-column/m-p/921251#M362792</link>
      <description>&lt;P&gt;The following code will set variable&amp;nbsp;&lt;CODE class=" language-sas"&gt;MultiForm&lt;/CODE&gt;&amp;nbsp;to 1 if for an ID more than one Form variable got a value of 1.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input id$ 1-3 FormA FormB FormC;
  infile datalines;
  datalines;
101 1 . . 
101 1 0 . 
102 1 0 . 
102 . 1 . 
103 . . 0 
103 . . 1 
104 1 0 . 
104 . . 1
105 . 1 . 
;
run;

proc sql;
/*  create table want as*/
  select i.*,sum(FormA,FormB,FormC)&amp;gt;1 as MultiForm
  from
  (
    select 
      id,
      max(FormA) as FormA,
      max(FormB) as FormB,
      max(FormC) as FormC
    from have
    group by id
  ) i
  ;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1711002653982.png" style="width: 323px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/94830iD43FC3CBF42A5455/image-dimensions/323x168?v=v2" width="323" height="168" role="button" title="Patrick_0-1711002653982.png" alt="Patrick_0-1711002653982.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2024 06:31:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/counting-data-across-column/m-p/921251#M362792</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-03-21T06:31:08Z</dc:date>
    </item>
    <item>
      <title>Re: counting data  across column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/counting-data-across-column/m-p/921292#M362811</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;based on your response, if I want to have a count of formA only, formB only, formC only and multi_form how will i get the frequency count?&amp;nbsp;&lt;/P&gt;&lt;P&gt;I guess what am saying is how would I count formAonly without counting (where 102=1) as part of formA.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please can I learn this using data step? Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2024 13:39:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/counting-data-across-column/m-p/921292#M362811</guid>
      <dc:creator>CathyVI</dc:creator>
      <dc:date>2024-03-21T13:39:45Z</dc:date>
    </item>
    <item>
      <title>Re: counting data  across column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/counting-data-across-column/m-p/921423#M362874</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/253321"&gt;@CathyVI&lt;/a&gt;&amp;nbsp;Below one way when using SQL&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
/*  create table want as*/
  select 
    *,
    ifn(MultiForm=1 and FormA=1,0,FormA) as FormA_only,
    ifn(MultiForm=1 and FormB=1,0,FormB) as FormB_only,
    ifn(MultiForm=1 and FormC=1,0,FormC) as FormC_only
  from
  (
    select 
      *,
      sum(FormA,FormB,FormC)&amp;gt;1 as MultiForm
    from
    (
      select 
        id,
        max(FormA) as FormA,
        max(FormB) as FormB,
        max(FormC) as FormC
      from have
      group by id
    ) 
  )
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Mar 2024 23:20:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/counting-data-across-column/m-p/921423#M362874</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-03-21T23:20:24Z</dc:date>
    </item>
    <item>
      <title>Re: counting data  across column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/counting-data-across-column/m-p/921452#M362888</link>
      <description>&lt;PRE&gt;data dummy;
input id$ 1-3 FormA FormB FormC ;
infile datalines ;
datalines;
101 1 0 . 
101 . 0 . 
102 1 0 . 
102 . 1 . 
103 . . 0 
103 . . 1 
104 1 0 . 
104 . . 1
105 . 1 . 
;
;
run;

data want;
	do until(last.id);
		set dummy;
		by id;
		if formA then _forma=1;
		if formB then _formb=1;
		if formC then _formc=1;
	end;
	if sum(of _form:)&amp;gt;1 then multiForm=1;
	else multiForm=0;
	if multiForm=0 then do;
		if _forma then formAOnly=1;
		else if _formB then formBOnly=1;
		else if _formC then formCOnly=1;
	end;
	output;
	drop _:;
run;&lt;/PRE&gt;&lt;P&gt;Can you try this?&lt;/P&gt;</description>
      <pubDate>Fri, 22 Mar 2024 08:06:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/counting-data-across-column/m-p/921452#M362888</guid>
      <dc:creator>Mazi</dc:creator>
      <dc:date>2024-03-22T08:06:27Z</dc:date>
    </item>
  </channel>
</rss>

