<?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: Creating new variable using proc means in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Creating-new-variable-using-proc-means/m-p/379560#M65579</link>
    <description>Thanks for your help.</description>
    <pubDate>Wed, 26 Jul 2017 20:45:54 GMT</pubDate>
    <dc:creator>Mica27</dc:creator>
    <dc:date>2017-07-26T20:45:54Z</dc:date>
    <item>
      <title>Creating new variable using proc means</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Creating-new-variable-using-proc-means/m-p/379545#M65575</link>
      <description>&lt;P&gt;Hello.&amp;nbsp; I have a data set with person-level wage data.&amp;nbsp; Each person's record also includes a state, month, and year variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to be able to generate the median wage for each state in a given month and then create a new variable with that value.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to do this directly via code and avoid copying from the output window?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using SAS 9.3.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for any help you can provide.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jul 2017 20:23:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Creating-new-variable-using-proc-means/m-p/379545#M65575</guid>
      <dc:creator>Mica27</dc:creator>
      <dc:date>2017-07-26T20:23:00Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new variable using proc means</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Creating-new-variable-using-proc-means/m-p/379547#M65576</link>
      <description>&lt;P&gt;you can do this by doing output statement. I have copied an example for you for below link&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www2.sas.com/proceedings/sugi29/240-29.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi29/240-29.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC MEANS DATA=SUGI.ELEC_ANNUAL NOPRINT;
VAR TOTREV TOTKWH TOTHRS;
OUTPUT OUT=SUGI2 sum(TOTREV TOTKWH) = sum_rev sum_kwh
mean(TOTREV) = mean_rev
median(TOTHRS) = median_hrs;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 26 Jul 2017 20:27:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Creating-new-variable-using-proc-means/m-p/379547#M65576</guid>
      <dc:creator>kiranv_</dc:creator>
      <dc:date>2017-07-26T20:27:30Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new variable using proc means</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Creating-new-variable-using-proc-means/m-p/379549#M65577</link>
      <description>&lt;P&gt;&lt;A href="https://github.com/statgeek/SAS-Tutorials/blob/master/proc_means_basic" target="_blank"&gt;https://github.com/statgeek/SAS-Tutorials/blob/master/proc_means_basic&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes, PROC MEANS has an OUTPUT statement that allows you to capture the output data.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may need to tweak the BY statement to get exactly what you want but the follow should help you get started.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc means data=have noprint;
BY STATE YEAR MONTH;
var wage;
output out=want median(wage) = median_wage;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/155958"&gt;@Mica27&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hello.&amp;nbsp; I have a data set with person-level wage data.&amp;nbsp; Each person's record also includes a state, month, and year variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to be able to generate the median wage for each state in a given month and then create a new variable with that value.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a way to do this directly via code and avoid copying from the output window?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am using SAS 9.3.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for any help you can provide.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jul 2017 20:30:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Creating-new-variable-using-proc-means/m-p/379549#M65577</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-07-26T20:30:05Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new variable using proc means</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Creating-new-variable-using-proc-means/m-p/379555#M65578</link>
      <description>&lt;P&gt;Thank you very much!&amp;nbsp; I will try this out.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jul 2017 20:44:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Creating-new-variable-using-proc-means/m-p/379555#M65578</guid>
      <dc:creator>Mica27</dc:creator>
      <dc:date>2017-07-26T20:44:44Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new variable using proc means</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Creating-new-variable-using-proc-means/m-p/379560#M65579</link>
      <description>Thanks for your help.</description>
      <pubDate>Wed, 26 Jul 2017 20:45:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Creating-new-variable-using-proc-means/m-p/379560#M65579</guid>
      <dc:creator>Mica27</dc:creator>
      <dc:date>2017-07-26T20:45:54Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new variable using proc means</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Creating-new-variable-using-proc-means/m-p/443160#M69328</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;can I use CLASS rather than BY command?&lt;/P&gt;&lt;P&gt;And How can I put the median_wage back to the original dataset? In another way, just add another variable containing the value I obtained from this MEANS step.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Mar 2018 02:33:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Creating-new-variable-using-proc-means/m-p/443160#M69328</guid>
      <dc:creator>yanshuai</dc:creator>
      <dc:date>2018-03-07T02:33:34Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new variable using proc means</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Creating-new-variable-using-proc-means/m-p/443368#M69339</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/188461"&gt;@yanshuai&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;can I use CLASS rather than BY command?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Try it and see. They are not exact replications of each other, so if you use CLASS you need to make other changes as well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/188461"&gt;@yanshuai&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And How can I put the median_wage back to the original dataset? In another way, just add another variable containing the value I obtained from this MEANS step.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;See the examples here:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/statgeek/SAS-Tutorials/blob/master/add_average_value_to_dataset.sas" target="_blank"&gt;https://github.com/statgeek/SAS-Tutorials/blob/master/add_average_value_to_dataset.sas&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Mar 2018 15:48:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Creating-new-variable-using-proc-means/m-p/443368#M69339</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-03-07T15:48:25Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new variable using proc means</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Creating-new-variable-using-proc-means/m-p/443456#M69342</link>
      <description>&lt;P&gt;Thank you Reeza!&lt;/P&gt;&lt;P&gt;I have been using SQL or MERGE to do this. But I am trying to find if new variable can be put back to the old table directly without creating new tables.&lt;/P&gt;&lt;P&gt;It seems it is inevitable.&lt;/P&gt;&lt;P&gt;Thank you all the same.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Mar 2018 18:54:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Creating-new-variable-using-proc-means/m-p/443456#M69342</guid>
      <dc:creator>yanshuai</dc:creator>
      <dc:date>2018-03-07T18:54:03Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new variable using proc means</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Creating-new-variable-using-proc-means/m-p/443459#M69343</link>
      <description>&lt;P&gt;The last SQL step does it automatically, but if you don't have SAS 9.4+ the median will not be correct.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Mar 2018 18:56:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Creating-new-variable-using-proc-means/m-p/443459#M69343</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-03-07T18:56:26Z</dc:date>
    </item>
  </channel>
</rss>

