<?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 Histogram for multiple choice question? in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Histogram-for-multiple-choice-question/m-p/803607#M33342</link>
    <description>&lt;P class=""&gt;Hey,&lt;/P&gt;&lt;P class=""&gt;I am analysing a questionnaire with multiple choice questions.&lt;/P&gt;&lt;P class=""&gt;My data looks this way:&lt;/P&gt;&lt;P class=""&gt;Var1 Var2 Var3 Var 4&lt;/P&gt;&lt;P class=""&gt;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P class=""&gt;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P class=""&gt;&amp;nbsp; 0 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P class=""&gt;….&lt;/P&gt;&lt;P class=""&gt;so in each row is a proband, and in each column X is 1, if the proband crossed field X in the question, and else 0.&lt;/P&gt;&lt;P class=""&gt;I want to plot a histogram/barplot, where the absolute values are shown, how often the fields are crossed.&lt;/P&gt;&lt;P class=""&gt;So in the above example I would like to get a histogram like:&lt;/P&gt;&lt;P class=""&gt;2 1 2 2&lt;/P&gt;&lt;P class=""&gt;so simply the colsums plotted as a histogram.&lt;/P&gt;&lt;P class=""&gt;How can I do this?&lt;/P&gt;</description>
    <pubDate>Wed, 23 Mar 2022 17:12:46 GMT</pubDate>
    <dc:creator>Lattecoffeegirl</dc:creator>
    <dc:date>2022-03-23T17:12:46Z</dc:date>
    <item>
      <title>Histogram for multiple choice question?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Histogram-for-multiple-choice-question/m-p/803607#M33342</link>
      <description>&lt;P class=""&gt;Hey,&lt;/P&gt;&lt;P class=""&gt;I am analysing a questionnaire with multiple choice questions.&lt;/P&gt;&lt;P class=""&gt;My data looks this way:&lt;/P&gt;&lt;P class=""&gt;Var1 Var2 Var3 Var 4&lt;/P&gt;&lt;P class=""&gt;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P class=""&gt;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P class=""&gt;&amp;nbsp; 0 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P class=""&gt;….&lt;/P&gt;&lt;P class=""&gt;so in each row is a proband, and in each column X is 1, if the proband crossed field X in the question, and else 0.&lt;/P&gt;&lt;P class=""&gt;I want to plot a histogram/barplot, where the absolute values are shown, how often the fields are crossed.&lt;/P&gt;&lt;P class=""&gt;So in the above example I would like to get a histogram like:&lt;/P&gt;&lt;P class=""&gt;2 1 2 2&lt;/P&gt;&lt;P class=""&gt;so simply the colsums plotted as a histogram.&lt;/P&gt;&lt;P class=""&gt;How can I do this?&lt;/P&gt;</description>
      <pubDate>Wed, 23 Mar 2022 17:12:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Histogram-for-multiple-choice-question/m-p/803607#M33342</guid>
      <dc:creator>Lattecoffeegirl</dc:creator>
      <dc:date>2022-03-23T17:12:46Z</dc:date>
    </item>
    <item>
      <title>Re: Histogram for multiple choice question?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Histogram-for-multiple-choice-question/m-p/803616#M33343</link>
      <description>&lt;P&gt;You can use PROC MEANS to sum the columns. Then transpose the sums from wide form to long form. (See &lt;A href="https://blogs.sas.com/content/iml/2011/01/31/reshaping-data-from-wide-to-long-format.html" target="_self"&gt;"Reshaping data from wide to long format"&lt;/A&gt;)&lt;/P&gt;
&lt;P&gt;You can then create a bar chart of the result, as follows:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Have;
input Var1 Var2 Var3 Var4;
datalines;
  1      0        0       1
  1      0        1       0
  0      1        1       1
  0      0        0       1
;

proc means data=Have;
output out=Sum(drop=_FREQ_) sum=;
run;

/* https://blogs.sas.com/content/iml/2011/01/31/reshaping-data-from-wide-to-long-format.html */
proc transpose data=Sum out=Want(rename=(Col1=Count));
by _TYPE_;
run;

proc sgplot data=Want;
vbar _Name_ / response=Count;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 23 Mar 2022 17:43:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Histogram-for-multiple-choice-question/m-p/803616#M33343</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2022-03-23T17:43:34Z</dc:date>
    </item>
    <item>
      <title>Re: Histogram for multiple choice question?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Histogram-for-multiple-choice-question/m-p/803617#M33344</link>
      <description>&lt;P&gt;First, I can't see a histogram working with this data, but a vertical bar chart would work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think that to get the var1 var2 var3 &lt;EM&gt;etc.&lt;/EM&gt; on the bottom of a plot, you need to reorganize your data into the long format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data re_organize;
    set have;
    array v v1-v4;
    do i=1 to dim(v);
        variable=vname(v(i));
        value=v(i);
        output;
     end;
     drop v1-v4;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And then you can get the bar chart you want from PROC SGPLOT&lt;/P&gt;</description>
      <pubDate>Wed, 23 Mar 2022 19:01:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Histogram-for-multiple-choice-question/m-p/803617#M33344</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-03-23T19:01:15Z</dc:date>
    </item>
    <item>
      <title>Re: Histogram for multiple choice question?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Histogram-for-multiple-choice-question/m-p/803625#M33346</link>
      <description>Thank you very much, this works perfectly in my case &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Wed, 23 Mar 2022 18:30:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Histogram-for-multiple-choice-question/m-p/803625#M33346</guid>
      <dc:creator>Lattecoffeegirl</dc:creator>
      <dc:date>2022-03-23T18:30:05Z</dc:date>
    </item>
    <item>
      <title>Re: Histogram for multiple choice question?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Histogram-for-multiple-choice-question/m-p/803633#M33347</link>
      <description>&lt;P&gt;A small additional question:&lt;/P&gt;&lt;P&gt;If my data now looks this way:&lt;/P&gt;&lt;LI-CODE lang="sas"&gt;data Have;
input Groupvar Var1 Var2 Var3 Var4;
datalines;
  1      1      0        0       1
  1      1      0        1       0
  2      0      1        1       1
  2      0      0        0       1
  2      0      0        1       1
  3      1      0        0       1
;&lt;/LI-CODE&gt;&lt;P&gt;so that I have an additional group variable. How would I implement this in your suggested code?&lt;/P&gt;&lt;P&gt;I was thinking about a group or by statement, but I cant figure out how to do this....&lt;/P&gt;&lt;P&gt;Thanks in advance &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Mar 2022 18:44:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Histogram-for-multiple-choice-question/m-p/803633#M33347</guid>
      <dc:creator>Lattecoffeegirl</dc:creator>
      <dc:date>2022-03-23T18:44:55Z</dc:date>
    </item>
    <item>
      <title>Re: Histogram for multiple choice question?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Histogram-for-multiple-choice-question/m-p/803635#M33348</link>
      <description>&lt;P&gt;In the code I provided, no changes are needed, however in PROC SGPLOT you would need&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;by groupvar;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;to get separate bar charts for each level of GROUPVAR&lt;/P&gt;</description>
      <pubDate>Wed, 23 Mar 2022 19:00:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Histogram-for-multiple-choice-question/m-p/803635#M33348</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-03-23T19:00:11Z</dc:date>
    </item>
    <item>
      <title>Re: Histogram for multiple choice question?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Histogram-for-multiple-choice-question/m-p/803770#M33357</link>
      <description>&lt;P&gt;what kind of graph are you wanting now? do you want all groups on the same graph or 3 separate graphs, one for each group?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Mar 2022 11:44:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Histogram-for-multiple-choice-question/m-p/803770#M33357</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2022-03-24T11:44:31Z</dc:date>
    </item>
    <item>
      <title>Re: Histogram for multiple choice question?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Histogram-for-multiple-choice-question/m-p/804301#M33409</link>
      <description>Your solution works perfectly fine, especially with the group, thank youuu &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Sat, 26 Mar 2022 21:54:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Histogram-for-multiple-choice-question/m-p/804301#M33409</guid>
      <dc:creator>Lattecoffeegirl</dc:creator>
      <dc:date>2022-03-26T21:54:39Z</dc:date>
    </item>
  </channel>
</rss>

