<?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: Collapse Dataset On Particular Character Variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Collapse-Dataset-On-Particular-Character-Variable/m-p/296488#M62137</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am not sure if you looking for this. Otherwise please elaborate&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;proc sql;
create table want as
select  i_X	
,avg(N) 
,avg(	Diff_2b) 
,avg(Ratio_2a)
,avg(	Slope_5050x_3)
,avg(	Slope_5050x_5)
from want
group by i_X;
quit;


&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 05 Sep 2016 09:59:21 GMT</pubDate>
    <dc:creator>RahulG</dc:creator>
    <dc:date>2016-09-05T09:59:21Z</dc:date>
    <item>
      <title>Collapse Dataset On Particular Character Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Collapse-Dataset-On-Particular-Character-Variable/m-p/296486#M62136</link>
      <description>&lt;P&gt;Please peruse following partial dataset:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;i_X	N	Diff_2b	Ratio_2a	Slope_5050x_3	Slope_5050x_5
_20206_6	25	0.48	-1.41	1.82	0.21
_20206_6	75	0.82	2.40	-0.39	0.91
_20206_6	92	1.09	0.80	-1.45	0.19
_22101_0	14	0.28	0.23	1.09	-0.22
_22101_0	85	1.31	0.22	0.30	-0.51
_22101_0	49	-1.19	-0.40	0.23	-0.52
_22101_0	20	1.58	-0.03	-0.70	1.49
_22101_0	64	-0.73	-0.13	1.05	-0.55
_23002_6	97	1.22	1.64	0.40	1.28
_23002_6	24	-1.72	-0.12	-0.61	0.07
_23002_6	80	-0.09	0.25	2.65	-0.31
_20502_6	45	-0.02	-0.48	-0.35	0.20
_20502_6	71	-1.91	0.61	-0.86	0.31
_20502_6	13	1.43	-0.71	0.97	-0.43
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I would like to collapse the dataset by the first column.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All the other numeric columns should be kept. &amp;nbsp;Values in those columns should be averages based on the character values being collapsed on.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any suggestions greatly appreciated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Nicholas Kormanik&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Sep 2016 09:50:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Collapse-Dataset-On-Particular-Character-Variable/m-p/296486#M62136</guid>
      <dc:creator>NKormanik</dc:creator>
      <dc:date>2016-09-05T09:50:06Z</dc:date>
    </item>
    <item>
      <title>Re: Collapse Dataset On Particular Character Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Collapse-Dataset-On-Particular-Character-Variable/m-p/296488#M62137</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am not sure if you looking for this. Otherwise please elaborate&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;proc sql;
create table want as
select  i_X	
,avg(N) 
,avg(	Diff_2b) 
,avg(Ratio_2a)
,avg(	Slope_5050x_3)
,avg(	Slope_5050x_5)
from want
group by i_X;
quit;


&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Sep 2016 09:59:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Collapse-Dataset-On-Particular-Character-Variable/m-p/296488#M62137</guid>
      <dc:creator>RahulG</dc:creator>
      <dc:date>2016-09-05T09:59:21Z</dc:date>
    </item>
    <item>
      <title>Re: Collapse Dataset On Particular Character Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Collapse-Dataset-On-Particular-Character-Variable/m-p/296505#M62140</link>
      <description>&lt;P&gt;Extend solutiom here by adding mean to the stats list.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/Base-SAS-Programming/For-members-of-a-character-column-give-sum-from-numerical-column/m-p/289748#M59859" target="_blank"&gt;https://communities.sas.com/t5/Base-SAS-Programming/For-members-of-a-character-column-give-sum-from-numerical-column/m-p/289748#M59859&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Sep 2016 11:11:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Collapse-Dataset-On-Particular-Character-Variable/m-p/296505#M62140</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-09-05T11:11:59Z</dc:date>
    </item>
    <item>
      <title>Re: Collapse Dataset On Particular Character Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Collapse-Dataset-On-Particular-Character-Variable/m-p/296533#M62157</link>
      <description>&lt;P&gt;Hi:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; In addition to Reeza's suggestion for SQL, you could also do this with TABULATE or REPORT. I prefer REPORT in something like this because the structure of the output dataset will be in the structure specified in your COLUMN statement and depending on your usage for the i_X variable, you will either get collapsing (GROUP usage) or ordering (ORDER usage).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Here's the PROC REPORT example. What you called N in your example, I called CNT because I wanted to use N in PROC REPORT to give me the number of rows.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;cynthia&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/4834iFEF78FBBDDA6CEC6/image-size/original?v=v2&amp;amp;px=-1" alt="report_slope.png" title="report_slope.png" border="0" /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Sep 2016 13:04:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Collapse-Dataset-On-Particular-Character-Variable/m-p/296533#M62157</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2016-09-05T13:04:24Z</dc:date>
    </item>
    <item>
      <title>Re: Collapse Dataset On Particular Character Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Collapse-Dataset-On-Particular-Character-Variable/m-p/296606#M62184</link>
      <description>&lt;P&gt;Beautifully done and presented, Cynthia. &amp;nbsp;And further demonstration of the powers of Proc Report.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks very much!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Sep 2016 23:56:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Collapse-Dataset-On-Particular-Character-Variable/m-p/296606#M62184</guid>
      <dc:creator>NKormanik</dc:creator>
      <dc:date>2016-09-05T23:56:59Z</dc:date>
    </item>
    <item>
      <title>Re: Collapse Dataset On Particular Character Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Collapse-Dataset-On-Particular-Character-Variable/m-p/296856#M62259</link>
      <description>&lt;P&gt;Cynthia, two follow-up questions, please:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) Your code as provided produces two adjacent columns (columns 2 and 3), "numrows" and "cnt". I would like to see as column 4 the product of those two columns, c2*c3, called, perhaps, "rows_x_cols". What would be the additional code to produce that?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) Most columns resulting contain way too many decimal places, making things a little hard to read. What would be the additional code to format various columns as having just three (3) decimal places?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;[Edit:] &amp;nbsp;I see now, from other posts, that I could add the following toward the top:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;format _numeric_ 9.3;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Adding this works to change the format of the report columns. &amp;nbsp;Super! &amp;nbsp;However, I would like to change the format of the exported dataset as well. &amp;nbsp;Should I do that as a subsequent data step?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks very much!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Sep 2016 23:55:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Collapse-Dataset-On-Particular-Character-Variable/m-p/296856#M62259</guid>
      <dc:creator>NKormanik</dc:creator>
      <dc:date>2016-09-06T23:55:48Z</dc:date>
    </item>
    <item>
      <title>Re: Collapse Dataset On Particular Character Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Collapse-Dataset-On-Particular-Character-Variable/m-p/296861#M62263</link>
      <description>&lt;P&gt;&lt;A href="http://www2.sas.com/proceedings/forum2008/079-2008.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/forum2008/079-2008.pdf&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Sep 2016 23:46:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Collapse-Dataset-On-Particular-Character-Variable/m-p/296861#M62263</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-09-06T23:46:29Z</dc:date>
    </item>
    <item>
      <title>Re: Collapse Dataset On Particular Character Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Collapse-Dataset-On-Particular-Character-Variable/m-p/296885#M62277</link>
      <description>HI:&lt;BR /&gt;  Do I remember correctly that you might be sending your output from the REPORT step or the dataset to Excel? If so, I would not look for the SAS FORMAT statement to impact ODS TAGSETS.EXCELXP or ODS EXCEL or even ODS CSV -- Excel is very persnickety about whether it uses SAS formats -- for the 2 XML based Excel destinations you can use TAGATTR to control the Microsoft format to be used by Excel. Most other SAS destinations (HTML, RTF, PDF will respect SAS formats).&lt;BR /&gt;&lt;BR /&gt;  To change the report, you only need to use a format statement as you show OR, if you want different formats for different variables -- as, for example if you have dates and numbers, then put your format= or f= in the DEFINE statement.&lt;BR /&gt; &lt;BR /&gt;If you want to "compute" a new report column based on the value of other columns on the report, such as you describe, then you would need to use a COMPUTE block. There are a lot of previous forum postings about the "left to right" rule of PROC REPORT and the special way you need  refer to analysis variables. However, in my example, numrows is an alias and CNT is an analysis variable.&lt;BR /&gt; &lt;BR /&gt;  So if he COLUMN statement changed to something like this:&lt;BR /&gt;column  grpvar n=numrows cnt newvar var3 var4 var5;&lt;BR /&gt; &lt;BR /&gt;Then you would need:&lt;BR /&gt;define newvar / computed;&lt;BR /&gt;&lt;BR /&gt;and then later in the PROC REPORT step:&lt;BR /&gt;compute newvar;&lt;BR /&gt;  newvar = numrows * cnt.sum;&lt;BR /&gt;endcomp;&lt;BR /&gt;&lt;BR /&gt;  I suggest you look in the PROC REPORT documenation for more examples of calculating report columns using a COMPUTE block.&lt;BR /&gt; &lt;BR /&gt;cynthia</description>
      <pubDate>Wed, 07 Sep 2016 02:37:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Collapse-Dataset-On-Particular-Character-Variable/m-p/296885#M62277</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2016-09-07T02:37:11Z</dc:date>
    </item>
    <item>
      <title>Re: Collapse Dataset On Particular Character Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Collapse-Dataset-On-Particular-Character-Variable/m-p/296894#M62285</link>
      <description>&lt;P&gt;Worked perfectly, Cynthia.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks a million!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Sep 2016 04:32:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Collapse-Dataset-On-Particular-Character-Variable/m-p/296894#M62285</guid>
      <dc:creator>NKormanik</dc:creator>
      <dc:date>2016-09-07T04:32:17Z</dc:date>
    </item>
  </channel>
</rss>

