<?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: Get mean, transpose and report etc. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Get-mean-transpose-and-report-etc/m-p/312900#M312967</link>
    <description>&lt;P&gt;I got it, I add id to get all columns. One more thing is that I ahve some missing values marked as ".".&lt;/P&gt;&lt;P&gt;How can set it as 0?&lt;/P&gt;</description>
    <pubDate>Sun, 20 Nov 2016 15:02:49 GMT</pubDate>
    <dc:creator>sas_newbie3</dc:creator>
    <dc:date>2016-11-20T15:02:49Z</dc:date>
    <item>
      <title>Get mean, transpose and report etc.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-mean-transpose-and-report-etc/m-p/312776#M312959</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I have the original dataset.&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/5911iCB89C68B6A7B3FC8/image-size/original?v=v2&amp;amp;px=-1" border="0" alt="1.PNG" title="1.PNG" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now I want to generate the report as&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/5912i1CE246D3F91DD048/image-size/original?v=v2&amp;amp;px=-1" border="0" alt="2.PNG" title="2.PNG" /&gt;&lt;/P&gt;&lt;P&gt;So I guess that my steps would be:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Get mean&lt;/LI&gt;&lt;LI&gt;Transpose from long to wide&lt;/LI&gt;&lt;LI&gt;Proc report add color.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;But I am stuck on the first two steps.&lt;/P&gt;&lt;P&gt;My poor code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc means data=myfile.old mean min max;
    class Lead_Studio_Name Genre;
    output out=myfile.mean_result;
run;

proc transpose data=myfile.mean_result;
   out=transpose_result;
   by Lead_Studio_Name;
   var Genre;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I know it is wrong, but I need advice.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Sat, 19 Nov 2016 03:43:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-mean-transpose-and-report-etc/m-p/312776#M312959</guid>
      <dc:creator>sas_newbie3</dc:creator>
      <dc:date>2016-11-19T03:43:59Z</dc:date>
    </item>
    <item>
      <title>Re: Get mean, transpose and report etc.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-mean-transpose-and-report-etc/m-p/312783#M312960</link>
      <description>&lt;P&gt;Well you've laid out your steps in broad terms but it might be worth fleshing it out to help figure out what you need.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Calculate mean, min and max for rotten tomatoes and audience scored&lt;/P&gt;
&lt;P&gt;2. Compute variable that is of the form (MIN#, MAX #)&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3. Since mean is in same column as min/max it has to be a character field, so convert mean to character as well.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;4. Now transpose, a data step with explicit output is probably better.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;5. Calculate counts by genre, PROC freq&lt;/P&gt;
&lt;P&gt;6. Transpose results from #5 via proc transpose&lt;/P&gt;
&lt;P&gt;7. Merge it in with data from #4&lt;/P&gt;
&lt;P&gt;8. Add conditional highlights with proc report.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Heres an example of 1-4:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc means data= have noprint NWAY;&lt;/P&gt;
&lt;P&gt;class studio ;&lt;/P&gt;
&lt;P&gt;var rotten user;&lt;/P&gt;
&lt;P&gt;output out=step1 min= rotten_min user_min max=rotten_max user_max mean=rotten_mean user_mean;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data step2&lt;/P&gt;
&lt;P&gt;set step1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Length Stat $12;&lt;/P&gt;
&lt;P&gt;Stat='Mean';&lt;/P&gt;
&lt;P&gt;rt_score = put(rotten_mean, 8.1);&lt;/P&gt;
&lt;P&gt;user_score = put(user_mean, 8.1);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;output;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Stat='(Min, Max)';&lt;/P&gt;
&lt;P&gt;rt_score = catx(', ', rotten_min, rotten_max);&lt;/P&gt;
&lt;P&gt;user_score=...;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;output;&lt;/P&gt;
&lt;P&gt;run;&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 19 Nov 2016 05:40:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-mean-transpose-and-report-etc/m-p/312783#M312960</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-11-19T05:40:07Z</dc:date>
    </item>
    <item>
      <title>Re: Get mean, transpose and report etc.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-mean-transpose-and-report-etc/m-p/312794#M312961</link>
      <description>&lt;PRE&gt;
Post your data as text, NOT picture.


proc sql;
create table temp1 as
select sex,'  Mean       ' as statistic,
       put(mean(weight),12.2) as score_weight length=20,
       put(mean(height),12.2) as score_height length=20
 from sashelp.class
  group by sex
union
select sex,'(Min,Max)',
       cats('(',put(min(weight),12.2),',',put(max(weight),12.2),')') ,
       cats('(',put(min(height),12.2),',',put(max(height),12.2),')') 
 from sashelp.class
  group by sex

order by 1,2;

quit;

proc freq data=sashelp.class noprint;
table sex*age/list out=freq;
run;
proc transpose data=freq out=temp2(drop=_:) prefix=age;
by sex;
var count;
id age;
run;
options missing='0';
data want;
 merge temp1 temp2;
 by sex;
run;
proc format;
value fmt
 0,.='red'
 1='yellow'
 2-high='green';
run;
proc report data=want nowd;
define statistic/style={just=center};
define score_:/style={just=center};
define age:/style={backgroundcolor=fmt.};
run;
&lt;/PRE&gt;</description>
      <pubDate>Sat, 19 Nov 2016 12:36:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-mean-transpose-and-report-etc/m-p/312794#M312961</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-11-19T12:36:58Z</dc:date>
    </item>
    <item>
      <title>Re: Get mean, transpose and report etc.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-mean-transpose-and-report-etc/m-p/312795#M312962</link>
      <description>&lt;PRE&gt;
proc sql;
create table temp1 as
select sex,'  Mean       ' as statistic,
       put(mean(weight),12.2) as score_weight length=20,
       put(mean(height),12.2) as score_height length=20
 from sashelp.class
  group by sex
union
select sex,'(Min,Max)',
       cats('(',put(min(weight),12.2),',',put(max(weight),12.2),')') ,
       cats('(',put(min(height),12.2),',',put(max(height),12.2),')') 
 from sashelp.class
  group by sex

order by 1,2;

quit;

proc freq data=sashelp.class noprint;
table sex*age/list out=freq;
run;
proc transpose data=freq out=temp2(drop=_:) prefix=age;
by sex;
var count;
id age;
run;
options missing='0';
data want;
 merge temp1 temp2;
 by sex;
run;
proc format;
value fmt
 0,.='red'
 1='yellow'
 2='green'
 3-high='purple';
run;
proc report data=want nowd;
define sex/order;
define statistic/style={just=center};
define score_:/style={just=center};
define age:/style={backgroundcolor=fmt.};
run;

&lt;/PRE&gt;</description>
      <pubDate>Sat, 19 Nov 2016 12:41:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-mean-transpose-and-report-etc/m-p/312795#M312962</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-11-19T12:41:43Z</dc:date>
    </item>
    <item>
      <title>Re: Get mean, transpose and report etc.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-mean-transpose-and-report-etc/m-p/312827#M312963</link>
      <description>&lt;P&gt;I am in the PROC TRANSPOSE step.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;proc transpose data=myfile.step3 out=myfile.step4(drop=_name_);&lt;BR /&gt; by Lead_Studio_Name;&lt;BR /&gt; var Genre;&lt;BR /&gt;run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;My question is in the original dataset, Genre has 9 but I only get 7 by the code. In the output dataset, I have COL1-COL7. Why?&lt;/P&gt;</description>
      <pubDate>Sun, 20 Nov 2016 03:00:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-mean-transpose-and-report-etc/m-p/312827#M312963</guid>
      <dc:creator>sas_newbie3</dc:creator>
      <dc:date>2016-11-20T03:00:40Z</dc:date>
    </item>
    <item>
      <title>Re: Get mean, transpose and report etc.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-mean-transpose-and-report-etc/m-p/312864#M312964</link>
      <description>&lt;P&gt;What does your log say?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 20 Nov 2016 04:59:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-mean-transpose-and-report-etc/m-p/312864#M312964</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-11-20T04:59:51Z</dc:date>
    </item>
    <item>
      <title>Re: Get mean, transpose and report etc.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-mean-transpose-and-report-etc/m-p/312875#M312965</link>
      <description>&lt;PRE&gt;85         proc freq data=myfile.have;
 NOTE: Data file MYFILE.have.DATA is in a format that is native to another host, or the file encoding does not match the 
       session encoding. Cross Environment Data Access will be used, which might require additional CPU resources and might reduce 
       performance.
 86            table Studio*User / out=myfile.step3;
 87         
 88            run;
 
 NOTE: There were 136 observations read from the data set MYFILE.have.
 NOTE: The data set MYFILE.STEP3 has 81 observations and 4 variables.
 NOTE: PROCEDURE FREQ used (Total process time):
       real time           0.83 seconds
       cpu time            0.79 seconds
       
 
 89         
 90         data myfile.step3(drop=percent);
 91         set myfile.step3;
 92         run;
 
 NOTE: There were 81 observations read from the data set MYFILE.STEP3.
 NOTE: The data set MYFILE.STEP3 has 81 observations and 3 variables.
 NOTE: DATA statement used (Total process time):
       real time           0.04 seconds
       cpu time            0.02 seconds
       
 
 93         
 94         
 95         proc transpose data=myfile.step3 out=myfile.step4(drop=_name_);
 96            by Studio;
 97            var User;
 98         run;
 
 NOTE: There were 81 observations read from the data set MYFILE.STEP3.
 NOTE: The data set MYFILE.STEP4 has 33 observations and 8 variables.
 NOTE: PROCEDURE TRANSPOSE used (Total process time):
       real time           0.04 seconds
       cpu time            0.02 seconds
       
 &lt;/PRE&gt;&lt;P&gt;The image of Step3 is&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/5919i3DFDE5D9F5CDB5D2/image-size/original?v=v2&amp;amp;px=-1" border="0" alt="3.PNG" title="3.PNG" /&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 20 Nov 2016 13:24:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-mean-transpose-and-report-etc/m-p/312875#M312965</guid>
      <dc:creator>sas_newbie3</dc:creator>
      <dc:date>2016-11-20T13:24:21Z</dc:date>
    </item>
    <item>
      <title>Re: Get mean, transpose and report etc.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-mean-transpose-and-report-etc/m-p/312877#M312966</link>
      <description>&lt;P&gt;The proc transpose is incorrect. VAR should reflect the variable (count) to be in new columns and you can use ID/IDlabel to generate appropriate variable names.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Give writing the code a shot and post back if you have issues.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 20 Nov 2016 14:12:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-mean-transpose-and-report-etc/m-p/312877#M312966</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-11-20T14:12:18Z</dc:date>
    </item>
    <item>
      <title>Re: Get mean, transpose and report etc.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-mean-transpose-and-report-etc/m-p/312900#M312967</link>
      <description>&lt;P&gt;I got it, I add id to get all columns. One more thing is that I ahve some missing values marked as ".".&lt;/P&gt;&lt;P&gt;How can set it as 0?&lt;/P&gt;</description>
      <pubDate>Sun, 20 Nov 2016 15:02:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-mean-transpose-and-report-etc/m-p/312900#M312967</guid>
      <dc:creator>sas_newbie3</dc:creator>
      <dc:date>2016-11-20T15:02:49Z</dc:date>
    </item>
    <item>
      <title>Re: Get mean, transpose and report etc.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-mean-transpose-and-report-etc/m-p/312902#M312968</link>
      <description>&lt;P&gt;You have to manually do that unfortunately.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use a datastep with an array to loop over your Genre and if missing set to 0&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 20 Nov 2016 15:04:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-mean-transpose-and-report-etc/m-p/312902#M312968</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-11-20T15:04:53Z</dc:date>
    </item>
    <item>
      <title>Re: Get mean, transpose and report etc.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-mean-transpose-and-report-etc/m-p/313145#M312969</link>
      <description>&lt;P&gt;Please explain the reasoning that you duplicate the counts for the Genre and have a separate row for the values of range of the ratings scores.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would generally expect a separate row to provide additional information. It seems more "natural" that the min/max appear on the same row and only have one row per studio. Which means that a single operation, either Proc Report or Tabulate would work.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Nov 2016 16:22:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-mean-transpose-and-report-etc/m-p/313145#M312969</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-11-21T16:22:08Z</dc:date>
    </item>
  </channel>
</rss>

