<?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: Problems with PROC TABULATE percentages for survey data in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Problems-with-PROC-TABULATE-percentages-for-survey-data/m-p/69745#M20063</link>
    <description>depending on how you want to solve this PCTSUM might do it.&lt;BR /&gt;
When you have 1 for yes and 0 for no in a column called resp01, the sum would be the count of yesses and the N would be total respondents(for that question) and mean and pctsum would provide what I think you seek.&lt;BR /&gt;
check with a table like&lt;BR /&gt;
table cat, resp01='responses'*( &lt;BR /&gt;
n='total responders' *f= comma7.&lt;BR /&gt;
sum='total yes'  *f= comma7.&lt;BR /&gt;
pctsum='response rate for this question'*f=5.1 &lt;BR /&gt;
pctn='rate of Yes over whole survey' *f= 5.&lt;BR /&gt;
mean='mean Q resp' * f=percent7.1 &lt;BR /&gt;
) /rts=40;&lt;BR /&gt;
 &lt;BR /&gt;
I like it when % formatting is natural&lt;BR /&gt;
 &lt;BR /&gt;
&lt;BR /&gt;
luck&lt;BR /&gt;
peterC</description>
    <pubDate>Sun, 05 Sep 2010 16:39:53 GMT</pubDate>
    <dc:creator>Peter_C</dc:creator>
    <dc:date>2010-09-05T16:39:53Z</dc:date>
    <item>
      <title>Problems with PROC TABULATE percentages for survey data</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Problems-with-PROC-TABULATE-percentages-for-survey-data/m-p/69743#M20061</link>
      <description>Hi all,&lt;BR /&gt;
I'm trying to analyze survey data of the 'mark all that apply' type questions.&lt;BR /&gt;
I've broken each question down to a series of yes/no responses :&lt;BR /&gt;
q1 q2 q3 q4 q5&lt;BR /&gt;
Y   N  N  Y  Y&lt;BR /&gt;
I then reformat the data and output a data set (exp) to feed to PROC TABULATE :&lt;BR /&gt;
This data set lists the labels of the questions that have a 'Y' response.  For example, the one observation above would expand into three observations :&lt;BR /&gt;
question 1&lt;BR /&gt;
question 4&lt;BR /&gt;
question 5&lt;BR /&gt;
Unfortunately, when I use Proc Tabulate and request counts and percentages for each question, the percentages are too low because they are using N for the *expanded* data set.&lt;BR /&gt;
&lt;BR /&gt;
Here is the code to expand the original data set  :&lt;BR /&gt;
&lt;BR /&gt;
data exp;&lt;BR /&gt;
  set main;&lt;BR /&gt;
  length cat $ 48;&lt;BR /&gt;
  array md{20} q1--q20;&lt;BR /&gt;
  do j = 1 to 20;&lt;BR /&gt;
    idx = j;&lt;BR /&gt;
    if md{j} = 'Y' then do;&lt;BR /&gt;
      cat = put(j,fgen.);&lt;BR /&gt;
      output;&lt;BR /&gt;
   end;&lt;BR /&gt;
end;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Note that the format fgen is simply 1 = 'Question 1'&lt;BR /&gt;
                                                   2 = 'Question 2'&lt;BR /&gt;
                                                   3 = 'Question 3' ...&lt;BR /&gt;
&lt;BR /&gt;
The tabulate procedure looks like this :&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
proc tabulate data = exp format=comma14. order=data;&lt;BR /&gt;
   class cat;&lt;BR /&gt;
 table cat,n="Yes responses" pctn*all="Percent" /   rts = 50;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
The first column - the counts - are accurate, BUT the percentages are all too low - ostensibley because the counts are being divided by the N for the expanded data set, not the original data set.&lt;BR /&gt;
Does anyone know a way around this ?  I've tried using the &amp;lt; &amp;gt; operator to change percent denominators, the ROWPCTN option - without success.&lt;BR /&gt;
Any help/hints would be appreciated.&lt;BR /&gt;
Barry Walton&lt;BR /&gt;
Barry.Walton@millersville.edu</description>
      <pubDate>Fri, 03 Sep 2010 12:35:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Problems-with-PROC-TABULATE-percentages-for-survey-data/m-p/69743#M20061</guid>
      <dc:creator>enginemane44</dc:creator>
      <dc:date>2010-09-03T12:35:20Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with PROC TABULATE percentages for survey data</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Problems-with-PROC-TABULATE-percentages-for-survey-data/m-p/69744#M20062</link>
      <description>Let me see if I understand.  You want the denominator to be the number of respondants for the question, but you have eliminated all of the 'N' values.  If you had Y and N in your data the ROWPCTN would work.&lt;BR /&gt;
[pre]*Build data;&lt;BR /&gt;
data survey;&lt;BR /&gt;
do ID = 1 to 4;&lt;BR /&gt;
   do question = 1 to 5;&lt;BR /&gt;
      if ranuni(999999)&amp;gt;.7 then resp='Y';&lt;BR /&gt;
      else resp='N';&lt;BR /&gt;
      if ranuni(99999)&amp;gt;.3 then output;&lt;BR /&gt;
   end;&lt;BR /&gt;
end;&lt;BR /&gt;
run;&lt;BR /&gt;
proc freq data=survey;&lt;BR /&gt;
table question*resp;&lt;BR /&gt;
run;&lt;BR /&gt;
proc tabulate data=survey;&lt;BR /&gt;
class question resp;&lt;BR /&gt;
table question,resp*(n rowpctn);&lt;BR /&gt;
run;[/pre]</description>
      <pubDate>Fri, 03 Sep 2010 20:56:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Problems-with-PROC-TABULATE-percentages-for-survey-data/m-p/69744#M20062</guid>
      <dc:creator>ArtC</dc:creator>
      <dc:date>2010-09-03T20:56:49Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with PROC TABULATE percentages for survey data</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Problems-with-PROC-TABULATE-percentages-for-survey-data/m-p/69745#M20063</link>
      <description>depending on how you want to solve this PCTSUM might do it.&lt;BR /&gt;
When you have 1 for yes and 0 for no in a column called resp01, the sum would be the count of yesses and the N would be total respondents(for that question) and mean and pctsum would provide what I think you seek.&lt;BR /&gt;
check with a table like&lt;BR /&gt;
table cat, resp01='responses'*( &lt;BR /&gt;
n='total responders' *f= comma7.&lt;BR /&gt;
sum='total yes'  *f= comma7.&lt;BR /&gt;
pctsum='response rate for this question'*f=5.1 &lt;BR /&gt;
pctn='rate of Yes over whole survey' *f= 5.&lt;BR /&gt;
mean='mean Q resp' * f=percent7.1 &lt;BR /&gt;
) /rts=40;&lt;BR /&gt;
 &lt;BR /&gt;
I like it when % formatting is natural&lt;BR /&gt;
 &lt;BR /&gt;
&lt;BR /&gt;
luck&lt;BR /&gt;
peterC</description>
      <pubDate>Sun, 05 Sep 2010 16:39:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Problems-with-PROC-TABULATE-percentages-for-survey-data/m-p/69745#M20063</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2010-09-05T16:39:53Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with PROC TABULATE percentages for survey data</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Problems-with-PROC-TABULATE-percentages-for-survey-data/m-p/69746#M20064</link>
      <description>ArtC,&lt;BR /&gt;
Yes, your code worked perfectly, and I got a nice tabulation of Yes and No responses with their respective percentages :&lt;BR /&gt;
                    Yes        No&lt;BR /&gt;
                     N  PCNT  N   PCNT&lt;BR /&gt;
Question 1    7   70 %    3   30 %&lt;BR /&gt;
Question 2    5   50 %    5   50 %&lt;BR /&gt;
...&lt;BR /&gt;
What I wanted to do is count Yes responses only *as a percent of the original data*.  Thus, the table would look like this :&lt;BR /&gt;
      Yes Responses&lt;BR /&gt;
Question 1   7  70%&lt;BR /&gt;
Question 2  5   50 %&lt;BR /&gt;
...&lt;BR /&gt;
The problem is when the data set is expanded, N increases and the percentages that appear are too low inasmuch as they are based on the N from the expanded data set, not the original data set.  I fiddled around with the &amp;lt;&amp;gt; option to specify a custom denominator - without success.  I'm running SAS 9.1 under Windows XP.&lt;BR /&gt;
Here is code that will demonstrate the problem.  Any ideas ?&lt;BR /&gt;
proc format ;&lt;BR /&gt;
&lt;BR /&gt;
value fgen 1 = 'Question 1'&lt;BR /&gt;
           2 = 'Question 2'&lt;BR /&gt;
		   3 = 'Question 3'&lt;BR /&gt;
		   4 = 'Question 4'&lt;BR /&gt;
		   5 = 'Question 5';&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
data main;&lt;BR /&gt;
input q1$ q2$ q3$ q4$ q5$;&lt;BR /&gt;
datalines;&lt;BR /&gt;
Y Y Y N N&lt;BR /&gt;
N N Y Y N&lt;BR /&gt;
N N Y N Y&lt;BR /&gt;
N N N Y Y&lt;BR /&gt;
Y Y Y Y Y&lt;BR /&gt;
N Y N Y Y&lt;BR /&gt;
Y Y Y N Y&lt;BR /&gt;
Y Y Y N N&lt;BR /&gt;
N N Y Y N&lt;BR /&gt;
Y N Y Y Y&lt;BR /&gt;
;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
proc print data = main;&lt;BR /&gt;
title 'Data set main';&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc freq data = main;&lt;BR /&gt;
tables q1--q5;&lt;BR /&gt;
title 'Test frequency counts';&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
data exp;   * Expand the data set to feed to Proc Tabulate ;&lt;BR /&gt;
  set main;&lt;BR /&gt;
  length cat $ 48;&lt;BR /&gt;
  array md{5} q1--q5;&lt;BR /&gt;
  do j = 1 to 5;&lt;BR /&gt;
    if md{j} = 'Y' then do;&lt;BR /&gt;
      cat = put(j,fgen.);&lt;BR /&gt;
	  idx = j;&lt;BR /&gt;
	  output;&lt;BR /&gt;
   end;&lt;BR /&gt;
end;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
proc sort data = exp;&lt;BR /&gt;
by idx;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
proc print data = exp;&lt;BR /&gt;
title 'Data set exp';&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
proc tabulate data = exp format=comma14. order=data;&lt;BR /&gt;
   class cat;&lt;BR /&gt;
   table cat,n="Yes responses" pctn*all="Percent" / box = 'Survey data' rts = 15;&lt;BR /&gt;
   label cat = 'Category';&lt;BR /&gt;
title "Tabulation of 'Mark all that apply' questons";&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Barry Walton&lt;BR /&gt;
Barry.Walton@millersville.edu</description>
      <pubDate>Wed, 08 Sep 2010 13:34:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Problems-with-PROC-TABULATE-percentages-for-survey-data/m-p/69746#M20064</guid>
      <dc:creator>enginemane44</dc:creator>
      <dc:date>2010-09-08T13:34:34Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with PROC TABULATE percentages for survey data</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Problems-with-PROC-TABULATE-percentages-for-survey-data/m-p/69747#M20065</link>
      <description>Using Peter's suggestion, I have modified my example.  Notice that RESP is now a 0,1 variable and a VAR statement has been included in the TABULATE step.&lt;BR /&gt;
[pre]data survey;&lt;BR /&gt;
   do ID = 1 to 14;&lt;BR /&gt;
      do question = 1 to 5;      &lt;BR /&gt;
         if ranuni(999999)&amp;gt;.4 then resp=1;      &lt;BR /&gt;
         else resp=0;      &lt;BR /&gt;
         if ranuni(99999)&amp;gt;.3 then output;   &lt;BR /&gt;
      end;&lt;BR /&gt;
   end;&lt;BR /&gt;
   run;&lt;BR /&gt;
&lt;BR /&gt;
proc tabulate data=survey;&lt;BR /&gt;
   class question;&lt;BR /&gt;
   var resp;&lt;BR /&gt;
   table question,&lt;BR /&gt;
         resp='responses'*(n='total responders' *f= comma7.&lt;BR /&gt;
                           sum='total yes' *f= comma7.&lt;BR /&gt;
                           pctsum='response rate for this question'*f=5.1 &lt;BR /&gt;
                           pctn='rate of Yes over whole survey' *f= 5.&lt;BR /&gt;
                           mean='mean Q resp' * f=percent7.1 &lt;BR /&gt;
                           ) /rts=40;&lt;BR /&gt;
   run;&lt;BR /&gt;
&lt;BR /&gt;
[/pre]</description>
      <pubDate>Wed, 08 Sep 2010 19:32:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Problems-with-PROC-TABULATE-percentages-for-survey-data/m-p/69747#M20065</guid>
      <dc:creator>ArtC</dc:creator>
      <dc:date>2010-09-08T19:32:49Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with PROC TABULATE percentages for survey data</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Problems-with-PROC-TABULATE-percentages-for-survey-data/m-p/69748#M20066</link>
      <description>To build on ArtC's example, if you just change your program that builds the dataset WORK.EXP (so that you have 1's and 0's for Y and N), you can use ArtC's code to see how the report looks with your data. There is no need to keep all 5 questions for every obs, because with this approach, you have essentially transposed the data so that instead of one observation/row with all 5 of the responses, you now have one row per response in the WORK.EXP dataset.&lt;BR /&gt;
 &lt;BR /&gt;
I did not repeat the data reading program (for WORK.MAIN), as that stayed the same, but I did change the code starting with DATA EXP step.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia&lt;BR /&gt;
[pre]&lt;BR /&gt;
                                  &lt;BR /&gt;
data exp(keep=orig_obs question resp idx char_resp); &lt;BR /&gt;
* Expand the data set to feed to Proc Tabulate ;&lt;BR /&gt;
** In this version of the data, create variables QUESTION and RESP;&lt;BR /&gt;
** per ArtC example. Also keep track of orig_obs number, ;&lt;BR /&gt;
** in case you have to go back and research any strange answers.;&lt;BR /&gt;
** Keep character version of response;&lt;BR /&gt;
** in CHAR_RESP variable. RESP variable will be 1 or 0;&lt;BR /&gt;
set main;&lt;BR /&gt;
orig_obs = _n_;&lt;BR /&gt;
                         &lt;BR /&gt;
length question cat $ 48 char_resp $1;&lt;BR /&gt;
  array md{5} q1--q5;&lt;BR /&gt;
  do j = 1 to 5;&lt;BR /&gt;
    if md{j} = 'Y' then resp=1;&lt;BR /&gt;
    else resp=0;&lt;BR /&gt;
    char_resp = upcase(md{j});&lt;BR /&gt;
    cat = put(j,fgen.);&lt;BR /&gt;
    question = put(j,fgen.);&lt;BR /&gt;
    idx = j;&lt;BR /&gt;
    output;&lt;BR /&gt;
  end;&lt;BR /&gt;
run;&lt;BR /&gt;
                                   &lt;BR /&gt;
proc print data = exp;&lt;BR /&gt;
title 'Data set exp';&lt;BR /&gt;
run;&lt;BR /&gt;
                         &lt;BR /&gt;
ods listing close;&lt;BR /&gt;
ods html file='c:\temp\tab_survey.html' style=sasweb;&lt;BR /&gt;
proc tabulate data=exp;&lt;BR /&gt;
   class question;&lt;BR /&gt;
   var resp;&lt;BR /&gt;
   table question,&lt;BR /&gt;
         resp='responses'*(n='total responders' *f= comma7.&lt;BR /&gt;
                           sum='total yes' *f= comma7.&lt;BR /&gt;
                           pctsum='response rate for this question'*f=5.1 &lt;BR /&gt;
                           pctn='rate of Yes over whole survey' *f= 5.&lt;BR /&gt;
                           mean='mean Q resp' * f=percent7.1 &lt;BR /&gt;
                           ) /rts=40;&lt;BR /&gt;
run;&lt;BR /&gt;
ods html close;&lt;BR /&gt;
&lt;BR /&gt;
[/pre]</description>
      <pubDate>Wed, 08 Sep 2010 20:33:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Problems-with-PROC-TABULATE-percentages-for-survey-data/m-p/69748#M20066</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2010-09-08T20:33:28Z</dc:date>
    </item>
  </channel>
</rss>

