<?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: reshaping wide to narrow using subsets of certain columns and summarizing other columns in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/reshaping-wide-to-narrow-using-subsets-of-certain-columns-and/m-p/815601#M81844</link>
    <description>&lt;P&gt;The observations in the output data set will have each food item, and the average rating. So 5 rows, 2 columns. (by final observation I'm referring to the input data set, since the final row has the values that can be used for calculating all of the average ratings).&lt;/P&gt;</description>
    <pubDate>Sun, 29 May 2022 14:12:50 GMT</pubDate>
    <dc:creator>blurple</dc:creator>
    <dc:date>2022-05-29T14:12:50Z</dc:date>
    <item>
      <title>reshaping wide to narrow using subsets of certain columns and summarizing other columns</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/reshaping-wide-to-narrow-using-subsets-of-certain-columns-and/m-p/815592#M81842</link>
      <description>&lt;P&gt;Hello, I'm very to new to SAS and I'm struggling with reshaping this data. I've created accumulating columns and counters for the first five columns (which are ratings collected from a survey). Now I need to create a summary table with just two variables: the food item and the average rating. For example, the new data set would have the observation arugula, and the final observation's value of tArug/nArug. What are the methods to do this?&lt;/P&gt;&lt;P&gt;First 5 observations:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="redpill_2-1653830809902.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/71851iF445AA97D3F17007/image-size/medium?v=v2&amp;amp;px=400" role="button" title="redpill_2-1653830809902.png" alt="redpill_2-1653830809902.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Last observations:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="redpill_0-1653833728927.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/71856iDF8C59914061B22B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="redpill_0-1653833728927.png" alt="redpill_0-1653833728927.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 29 May 2022 14:16:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/reshaping-wide-to-narrow-using-subsets-of-certain-columns-and/m-p/815592#M81842</guid>
      <dc:creator>blurple</dc:creator>
      <dc:date>2022-05-29T14:16:00Z</dc:date>
    </item>
    <item>
      <title>Re: reshaping wide to narrow using subsets of certain columns and summarizing other columns</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/reshaping-wide-to-narrow-using-subsets-of-certain-columns-and/m-p/815599#M81843</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/425389"&gt;@blurple&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;For example, the new data set would have the observation arugula, and the final observation's value of tArug/nArug. What are the methods to do this?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So no PineNut or Squash in the output data set?&lt;/P&gt;</description>
      <pubDate>Sun, 29 May 2022 14:02:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/reshaping-wide-to-narrow-using-subsets-of-certain-columns-and/m-p/815599#M81843</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-05-29T14:02:20Z</dc:date>
    </item>
    <item>
      <title>Re: reshaping wide to narrow using subsets of certain columns and summarizing other columns</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/reshaping-wide-to-narrow-using-subsets-of-certain-columns-and/m-p/815601#M81844</link>
      <description>&lt;P&gt;The observations in the output data set will have each food item, and the average rating. So 5 rows, 2 columns. (by final observation I'm referring to the input data set, since the final row has the values that can be used for calculating all of the average ratings).&lt;/P&gt;</description>
      <pubDate>Sun, 29 May 2022 14:12:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/reshaping-wide-to-narrow-using-subsets-of-certain-columns-and/m-p/815601#M81844</guid>
      <dc:creator>blurple</dc:creator>
      <dc:date>2022-05-29T14:12:50Z</dc:date>
    </item>
    <item>
      <title>Re: reshaping wide to narrow using subsets of certain columns and summarizing other columns</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/reshaping-wide-to-narrow-using-subsets-of-certain-columns-and/m-p/815613#M81845</link>
      <description>&lt;P&gt;Show me the exact output data set you want for those five rows you presented originally.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, since we can't write code to use data in a screen capture, please provide (a portion of) the data as &lt;FONT color="#FF0000"&gt;working&lt;/FONT&gt; SAS data step code which you can type in yourself, or follow &lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;these instructions&lt;/A&gt;. Do not provide the data in other forms.&lt;/P&gt;</description>
      <pubDate>Sun, 29 May 2022 14:23:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/reshaping-wide-to-narrow-using-subsets-of-certain-columns-and/m-p/815613#M81845</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-05-29T14:23:36Z</dc:date>
    </item>
    <item>
      <title>Re: reshaping wide to narrow using subsets of certain columns and summarizing other columns</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/reshaping-wide-to-narrow-using-subsets-of-certain-columns-and/m-p/815619#M81846</link>
      <description>&lt;PRE&gt;&lt;CODE class=""&gt;data work.toppings;
infile datalines delimiter=',' dsd missover;
input Arugula PineNut;
datalines;
1,3
5,4
4,2
5,3
3,5
,4
2,
;
run;

data work.accum;
set work.toppings;
tArug+Arugula;
tPine+PineNut;
if Arugula ne '' then nArug+1;
if PineNut ne '' then nPine+1;
run;


&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;(side note: can I do the above two in one data step? the accumulation code seems to be the problem when I put those lines in the first data step)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is how I want the summarized output to look:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="redpill_2-1653838246066.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/71863i3E447F6C37FC80C6/image-size/medium?v=v2&amp;amp;px=400" role="button" title="redpill_2-1653838246066.png" alt="redpill_2-1653838246066.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 29 May 2022 15:31:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/reshaping-wide-to-narrow-using-subsets-of-certain-columns-and/m-p/815619#M81846</guid>
      <dc:creator>blurple</dc:creator>
      <dc:date>2022-05-29T15:31:50Z</dc:date>
    </item>
    <item>
      <title>Re: reshaping wide to narrow using subsets of certain columns and summarizing other columns</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/reshaping-wide-to-narrow-using-subsets-of-certain-columns-and/m-p/815621#M81847</link>
      <description>&lt;P&gt;Just use PROC MEANS.&amp;nbsp; Why re-invent the wheel?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data toppings;
  input Arugula PineNut;
datalines;
1 3
5 4
4 2
5 3
3 5
. 4
2 .
;

proc means data=toppings N Nmiss Sum Mean Min Max ;
  var Arugula PineNut;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1653839379344.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/71864i99EE8788C04F7050/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1653839379344.png" alt="Tom_0-1653839379344.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 29 May 2022 15:49:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/reshaping-wide-to-narrow-using-subsets-of-certain-columns-and/m-p/815621#M81847</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-05-29T15:49:46Z</dc:date>
    </item>
    <item>
      <title>Re: reshaping wide to narrow using subsets of certain columns and summarizing other columns</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/reshaping-wide-to-narrow-using-subsets-of-certain-columns-and/m-p/815625#M81849</link>
      <description>&lt;P&gt;Thanks, that makes sense and it's a lot easier.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However I'd still like to learn other method(s).&lt;/P&gt;</description>
      <pubDate>Sun, 29 May 2022 16:42:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/reshaping-wide-to-narrow-using-subsets-of-certain-columns-and/m-p/815625#M81849</guid>
      <dc:creator>blurple</dc:creator>
      <dc:date>2022-05-29T16:42:08Z</dc:date>
    </item>
    <item>
      <title>Re: reshaping wide to narrow using subsets of certain columns and summarizing other columns</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/reshaping-wide-to-narrow-using-subsets-of-certain-columns-and/m-p/815626#M81850</link>
      <description>&lt;P&gt;In your data step you just want to keep the last observation.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;An easy way to do that is with the END= option on the SET statement.&lt;/P&gt;
&lt;P&gt;By adding an explicit OUTPUT statement only that final observation will be written to WANT.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have end=eof;
  .... do your accumulation logic ...
  if eof then do;
     ... Now do the division to make rate out of SUM and NOBS ...
     output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 29 May 2022 16:50:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/reshaping-wide-to-narrow-using-subsets-of-certain-columns-and/m-p/815626#M81850</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-05-29T16:50:56Z</dc:date>
    </item>
  </channel>
</rss>

