<?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: Dynamic SAS program to calculate mean per group for multiple numeric variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-SAS-program-to-calculate-mean-per-group-for-multiple/m-p/784748#M250418</link>
    <description>So proc means with colon option on the VAR statement?&lt;BR /&gt;&lt;BR /&gt;proc mean data=have MEAN ;&lt;BR /&gt;by ID;&lt;BR /&gt;var Y:;&lt;BR /&gt;output out=want1 mean= /autoname autolabel;&lt;BR /&gt;ods output summary = want2;&lt;BR /&gt;run;</description>
    <pubDate>Tue, 07 Dec 2021 20:20:16 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2021-12-07T20:20:16Z</dc:date>
    <item>
      <title>Dynamic SAS program to calculate mean per group for multiple numeric variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-SAS-program-to-calculate-mean-per-group-for-multiple/m-p/784746#M250416</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I want to creata a dynamic program that calculate for each category of Z the mean (average) of each Y variable.&lt;/P&gt;
&lt;P&gt;The issue is that in this case have 3 Y variables&amp;nbsp; (&lt;CODE class=" language-sas"&gt; Y202101 Y202103  Y202105)&amp;nbsp;&amp;nbsp;but&amp;nbsp;in&amp;nbsp;another&amp;nbsp;time&amp;nbsp;of&amp;nbsp;running&amp;nbsp;might&amp;nbsp;have&amp;nbsp;different&amp;nbsp;Y&amp;nbsp;variables&amp;nbsp;.&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;I&amp;nbsp;would&amp;nbsp;like&amp;nbsp;to&amp;nbsp;create&amp;nbsp;a&amp;nbsp;program&amp;nbsp;that&amp;nbsp;is&amp;nbsp;dynamic&amp;nbsp;and&amp;nbsp;adjust&amp;nbsp;itself&amp;nbsp;to&amp;nbsp;situation&amp;nbsp;when&amp;nbsp;there&amp;nbsp;are&amp;nbsp;&amp;nbsp;different&amp;nbsp;Y&amp;nbsp;variables&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have;
input ID Z $ Y202101 Y202103  Y202105;
cards;
1	A	2	3	8
2	A	4	9	2
3	A	6	6	7
4	B	8	4	4
5	B	10	5	3
6	C	8	8	2
7	C	6	2	5
8	C	4	4	6
9	D	2	8	5
;
Run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Dec 2021 20:17:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-SAS-program-to-calculate-mean-per-group-for-multiple/m-p/784746#M250416</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-12-07T20:17:57Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic SAS program to calculate mean per group for multiple numeric variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-SAS-program-to-calculate-mean-per-group-for-multiple/m-p/784748#M250418</link>
      <description>So proc means with colon option on the VAR statement?&lt;BR /&gt;&lt;BR /&gt;proc mean data=have MEAN ;&lt;BR /&gt;by ID;&lt;BR /&gt;var Y:;&lt;BR /&gt;output out=want1 mean= /autoname autolabel;&lt;BR /&gt;ods output summary = want2;&lt;BR /&gt;run;</description>
      <pubDate>Tue, 07 Dec 2021 20:20:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-SAS-program-to-calculate-mean-per-group-for-multiple/m-p/784748#M250418</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-12-07T20:20:16Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic SAS program to calculate mean per group for multiple numeric variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-SAS-program-to-calculate-mean-per-group-for-multiple/m-p/784771#M250430</link>
      <description>&lt;P&gt;Which is a fine solution as long as you don't have (dynamically) a character variable in the data set whose name begins with Y. And then you get an error.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;The better solution, which we have recommended many times to &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;, and which I recommend to everyone, is to use a long data set instead of a wide data set. In the long data set, you have a variable named VALUE (or anything else you like) and a variable named MONTH, and then PROC SUMMARY/PROC MEANS will work with whatever values it finds in MONTH, dynamically, and go ahead and do the proper computations. And with the long data set, if you need a report where the months are columns, this is easy (and dynamic) via PROC REPORT.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I again urge you,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;to embrace the long data set approach, rather than continually getting stuck trying to handle wide data sets.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Dec 2021 21:56:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-SAS-program-to-calculate-mean-per-group-for-multiple/m-p/784771#M250430</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-12-07T21:56:00Z</dc:date>
    </item>
  </channel>
</rss>

