<?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: Transponse and add average - a solution, but maybe not the most effective!?! in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Transponse-and-add-average/m-p/335303#M272313</link>
    <description>&lt;P&gt;Now I got what I need, however I feel that I&amp;nbsp;have choosen an very ineffective way.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After creating asn sortin the main data table "studentrates"&lt;/P&gt;&lt;P&gt;-I sort&lt;/P&gt;&lt;P&gt;- Transpones&lt;/P&gt;&lt;P&gt;- Calculate the mean and store that result into data set&lt;/P&gt;&lt;P&gt;-merge the Transponse with the mean&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I feel that this is very time consuming, at least compared with&amp;nbsp;&amp;nbsp;Excel/SQL. I would appreciate a suggestion how to mak this smaler and faster.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;*code;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data studentrates;&lt;BR /&gt;input x ID Year rate ;&lt;BR /&gt;datalines;&lt;BR /&gt;1 1 2010 1&lt;BR /&gt;2 1 2011 2&lt;BR /&gt;3 1 2012 1&lt;BR /&gt;4 2 2010 4&lt;BR /&gt;5 2 2011 3&lt;BR /&gt;6 2 2012 2&lt;BR /&gt;7 3 2012 2&lt;BR /&gt;8 1 2013 1&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sort data =studentrates;&lt;BR /&gt;by ID;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;*create a transponsed table of all students rates;&lt;BR /&gt;proc transponse data=studentrates out=Trans_rates (drop= _NAME_) ;&lt;BR /&gt;by ID;&lt;BR /&gt;var rate;&lt;BR /&gt;id Year;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;*calculate means and store them in data set;&lt;BR /&gt;ods exclude all;&lt;BR /&gt;proc means data= studentrates mean;&lt;BR /&gt;class ID;&lt;BR /&gt;var rate ;&lt;BR /&gt;ods output Summary=rates_mean;&lt;BR /&gt;run;&lt;BR /&gt;ods exclude none;&lt;BR /&gt;&lt;BR /&gt;data Merge_Trans_rates;&lt;BR /&gt;merge Trans_rates (in=a) rates_mean (in=b);&lt;BR /&gt;by id;&lt;BR /&gt;run;&lt;BR /&gt;proc print data=Merge_Trans_rates;&lt;BR /&gt;run;&lt;/P&gt;</description>
    <pubDate>Thu, 23 Feb 2017 15:09:43 GMT</pubDate>
    <dc:creator>Newbe11</dc:creator>
    <dc:date>2017-02-23T15:09:43Z</dc:date>
    <item>
      <title>Transponse and add average</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transponse-and-add-average/m-p/335233#M272308</link>
      <description>&lt;P&gt;I like to transponse the following dataset called student, which works so far.&lt;/P&gt;&lt;P&gt;input n ID Year$ rate;&lt;/P&gt;&lt;P&gt;datalines;&lt;BR /&gt;1 1 2010 1&lt;BR /&gt;2 1 2011 2&lt;BR /&gt;3 1 2012 1&lt;BR /&gt;4 2 2010 4&lt;BR /&gt;5 2 2011 3&lt;BR /&gt;6 2 2012 2&lt;BR /&gt;7 3 2012 2&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;with the procedure&lt;/P&gt;&lt;P&gt;proc transponse data=student;&amp;nbsp;out=Zeugnis (drop= _NAME_) ;&lt;BR /&gt;by ID;&lt;BR /&gt;var rate;&lt;BR /&gt;id Year;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Result looks like this.&amp;nbsp;&lt;/P&gt;&lt;P&gt;obs &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ID &amp;nbsp; _2010 &amp;nbsp; &amp;nbsp; _2011 &amp;nbsp;_2012 &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2 &amp;nbsp; &amp;nbsp; &amp;nbsp;4 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3 &amp;nbsp; &amp;nbsp; &amp;nbsp;. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now I would like to add the Average colum to the end the display the average rate for each ID.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ID &amp;nbsp; _2010 &amp;nbsp; &amp;nbsp; _2011 &amp;nbsp;_2012 &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;Average&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;1.66&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; 2 &amp;nbsp; &amp;nbsp; &amp;nbsp;4 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;3&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;3 &amp;nbsp; &amp;nbsp; &amp;nbsp; 3 &amp;nbsp; &amp;nbsp; &amp;nbsp;. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;STRONG&gt;2&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you sugest a solution for this, if possible a simple line in the transponse procedure?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried to add this line, but it doies not work: &amp;nbsp;&lt;STRONG&gt; AVERAGE=mean(rate);&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 23 Feb 2017 10:45:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transponse-and-add-average/m-p/335233#M272308</guid>
      <dc:creator>Newbe11</dc:creator>
      <dc:date>2017-02-23T10:45:27Z</dc:date>
    </item>
    <item>
      <title>Re: Transponse and add average</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transponse-and-add-average/m-p/335234#M272309</link>
      <description>&lt;P&gt;Add a row to your original dataset with the average, you can do that in many ways, then transpose the dataset up. &amp;nbsp;Quite straightforward. &amp;nbsp;I would advise against going with the transposed idea however, unless its for an output report as that will make all your coding form there on harder.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Feb 2017 10:49:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transponse-and-add-average/m-p/335234#M272309</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-02-23T10:49:17Z</dc:date>
    </item>
    <item>
      <title>Re: Transponse and add average</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transponse-and-add-average/m-p/335235#M272310</link>
      <description>&lt;P&gt;Thanks for your advise!&amp;nbsp;&lt;/P&gt;&lt;P&gt;Supposed, that this is the output and the source is a linked file:&lt;/P&gt;&lt;P&gt;would you also recomend to make a copy with the average first and then run the transponse?&lt;/P&gt;&lt;P&gt;Is it only hard or simply inpossible to make calculations in the Transponse proc?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Feb 2017 10:59:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transponse-and-add-average/m-p/335235#M272310</guid>
      <dc:creator>Newbe11</dc:creator>
      <dc:date>2017-02-23T10:59:48Z</dc:date>
    </item>
    <item>
      <title>Re: Transponse and add average</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transponse-and-add-average/m-p/335238#M272311</link>
      <description>&lt;P&gt;I don't know what this means; "&lt;SPAN&gt;Supposed, that this is the output and the source is a linked file:&lt;/SPAN&gt;"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyways, you can do things on transposed data with arrays, its just more effort:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  array vals{3} _2010 _2011 _2012;
  av=mean(of vals{*});
run;&lt;/PRE&gt;
&lt;P&gt;Save yourself a lot of coding however and ditch the "Excel" way of thinking.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Feb 2017 11:08:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transponse-and-add-average/m-p/335238#M272311</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-02-23T11:08:02Z</dc:date>
    </item>
    <item>
      <title>Re: Transponse and add average</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transponse-and-add-average/m-p/335247#M272312</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data x;
input obs         ID   _2010     _2011  _2012 ;
mean=mean(of _:);
cards;    
1              1      1              2          1           
2              2      4              3          2             
3              3      .              .            2     
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 Feb 2017 11:29:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transponse-and-add-average/m-p/335247#M272312</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-02-23T11:29:11Z</dc:date>
    </item>
    <item>
      <title>Re: Transponse and add average - a solution, but maybe not the most effective!?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transponse-and-add-average/m-p/335303#M272313</link>
      <description>&lt;P&gt;Now I got what I need, however I feel that I&amp;nbsp;have choosen an very ineffective way.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After creating asn sortin the main data table "studentrates"&lt;/P&gt;&lt;P&gt;-I sort&lt;/P&gt;&lt;P&gt;- Transpones&lt;/P&gt;&lt;P&gt;- Calculate the mean and store that result into data set&lt;/P&gt;&lt;P&gt;-merge the Transponse with the mean&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I feel that this is very time consuming, at least compared with&amp;nbsp;&amp;nbsp;Excel/SQL. I would appreciate a suggestion how to mak this smaler and faster.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;*code;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data studentrates;&lt;BR /&gt;input x ID Year rate ;&lt;BR /&gt;datalines;&lt;BR /&gt;1 1 2010 1&lt;BR /&gt;2 1 2011 2&lt;BR /&gt;3 1 2012 1&lt;BR /&gt;4 2 2010 4&lt;BR /&gt;5 2 2011 3&lt;BR /&gt;6 2 2012 2&lt;BR /&gt;7 3 2012 2&lt;BR /&gt;8 1 2013 1&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sort data =studentrates;&lt;BR /&gt;by ID;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;*create a transponsed table of all students rates;&lt;BR /&gt;proc transponse data=studentrates out=Trans_rates (drop= _NAME_) ;&lt;BR /&gt;by ID;&lt;BR /&gt;var rate;&lt;BR /&gt;id Year;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;*calculate means and store them in data set;&lt;BR /&gt;ods exclude all;&lt;BR /&gt;proc means data= studentrates mean;&lt;BR /&gt;class ID;&lt;BR /&gt;var rate ;&lt;BR /&gt;ods output Summary=rates_mean;&lt;BR /&gt;run;&lt;BR /&gt;ods exclude none;&lt;BR /&gt;&lt;BR /&gt;data Merge_Trans_rates;&lt;BR /&gt;merge Trans_rates (in=a) rates_mean (in=b);&lt;BR /&gt;by id;&lt;BR /&gt;run;&lt;BR /&gt;proc print data=Merge_Trans_rates;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Feb 2017 15:09:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transponse-and-add-average/m-p/335303#M272313</guid>
      <dc:creator>Newbe11</dc:creator>
      <dc:date>2017-02-23T15:09:43Z</dc:date>
    </item>
    <item>
      <title>Re: Transponse and add average - a solution, but maybe not the most effective!?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transponse-and-add-average/m-p/335324#M272314</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;has already provided with the answer, here is the cod ewith your test data. &amp;nbsp;Note that this "Excel" thinking of having things across the page (and putting "data" as the column names) is the reason your having trouble and willmake your coding harder. &amp;nbsp;If you know SQL programming you should be competant in working with normalised data and the only time you would transpose is if an output report is needed like that.&lt;/P&gt;
&lt;PRE&gt;data studentrates;
input x ID Year rate ;
datalines;
1 1 2010 1
2 1 2011 2
3 1 2012 1
4 2 2010 4
5 2 2011 3
6 2 2012 2
7 3 2012 2
8 1 2013 1
;
run;

proc sort data=studentrates;
  by id year;
run;

proc transpose data=studentrates out=want;
  by id;
  var rate;
  id year;
  idlabel year;
run;

data want;
  set want (drop=_name_);
  avg=mean(of _:);
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 Feb 2017 15:51:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transponse-and-add-average/m-p/335324#M272314</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-02-23T15:51:05Z</dc:date>
    </item>
    <item>
      <title>Re: Transponse and add average - a solution, but maybe not the most effective!?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transponse-and-add-average/m-p/335417#M272315</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input x ID Year rate ;
datalines;
1 1 2010 1
2 1 2011 2
3 1 2012 1
4 2 2010 4
5 2 2011 3
6 2 2012 2
7 3 2012 2
8 1 2013 1
;
run;


Ods Output Observed=havsum(Rename=(Label=Product sum=Total));
Proc Corresp Data=have Observed dim=1;
   Table id, year;
   weight rate;
run;quit;

data want;
  set havsum;
  avg=mean(of _:);
run;quit;

Up to 40 obs WORK.WANT total obs=4

Obs    PRODUCT    _2010    _2011    _2012    _2013    TOTAL     AVG

 1       1          1        2        1        1         5     1.25
 2       2          4        3        2        0         9     2.25
 3       3          0        0        2        0         2     0.50
 4       Sum        5        5        5        1        16     4.00


&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 Feb 2017 21:20:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transponse-and-add-average/m-p/335417#M272315</guid>
      <dc:creator>rogerjdeangelis</dc:creator>
      <dc:date>2017-02-23T21:20:13Z</dc:date>
    </item>
  </channel>
</rss>

