<?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: Two Way Proc Report in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Two-Way-Proc-Report/m-p/390876#M66176</link>
    <description>&lt;P&gt;Yes, then you need to apply sorts to the data:&lt;/P&gt;
&lt;PRE&gt;data have;&lt;BR /&gt; input market_area $ market_region $ customer_id;&lt;BR /&gt;datalines; &lt;BR /&gt;east A 12&lt;BR /&gt;east A 13&lt;BR /&gt;east B 10&lt;BR /&gt;east C 17&lt;BR /&gt;west A 12&lt;BR /&gt;west A 13&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt; create table WANT as&lt;BR /&gt; select COALESCE(MARKET_REGION,MARKET_AREA) as COL1,&lt;BR /&gt;        RESULT &lt;BR /&gt; from   (select MARKET_AREA,&lt;BR /&gt;                "" as MARKET_REGION,&lt;BR /&gt;                count(CUSTOMER_ID) as RESULT&lt;BR /&gt;         from HAVE&lt;BR /&gt;         group by MARKET_AREA&lt;BR /&gt;         union all&lt;BR /&gt;         select MARKET_AREA,&lt;BR /&gt;                MARKET_REGION,&lt;BR /&gt;                count(CUSTOMER_ID) as RESULT&lt;BR /&gt;         from HAVE&lt;BR /&gt;         group by MARKET_AREA,&lt;BR /&gt;                  MARKET_REGION)&lt;BR /&gt; order by MARKET_AREA,MARKET_REGION;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 25 Aug 2017 11:08:20 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2017-08-25T11:08:20Z</dc:date>
    <item>
      <title>Two Way Proc Report</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Two-Way-Proc-Report/m-p/390868#M66173</link>
      <description>&lt;P&gt;I am new SAS EG and trying to create proc report using charcter Varibles,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table look like below,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;market_Area &amp;nbsp;Market_Region &amp;nbsp;Customer_Id&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;east &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;A &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;12&lt;/P&gt;&lt;P&gt;east &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;A &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; 13&lt;/P&gt;&lt;P&gt;east &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;B &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; 10&lt;/P&gt;&lt;P&gt;east &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; C &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;17&lt;/P&gt;&lt;P&gt;&amp;nbsp;and so on&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need report like,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Area &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Count(Customer)&lt;/P&gt;&lt;P&gt;East &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4&lt;/P&gt;&lt;P&gt;&amp;nbsp;A &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;&amp;nbsp;B &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;C &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Like this for all regions,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc report data=Data_Have;&lt;BR /&gt;column Market_Area Market_Region&amp;nbsp;Customer_Id;&lt;BR /&gt;define Market_Area/group;&lt;/P&gt;&lt;P&gt;define Market_Region/group;&lt;BR /&gt;define &lt;SPAN&gt;Customer_Id&lt;/SPAN&gt;/sum "Sum of Distinct" width=8;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But its not working, Kndly Help&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Aug 2017 10:16:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Two-Way-Proc-Report/m-p/390868#M66173</guid>
      <dc:creator>Gangi</dc:creator>
      <dc:date>2017-08-25T10:16:05Z</dc:date>
    </item>
    <item>
      <title>Re: Two Way Proc Report</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Two-Way-Proc-Report/m-p/390872#M66174</link>
      <description>&lt;P&gt;I tend to avoid doing data manipulations in proc report. &amp;nbsp;Especially when doing more complex ones it is just simpler. &amp;nbsp;For your problem:&lt;/P&gt;
&lt;PRE&gt;data have;
  input market_area $ market_region $ customer_id;
datalines; 
east A 12
east A 13
east B 10
east C 17
;
run;

proc sql;
  create table WANT as
  select  MARKET_AREA as COL1,
          count(CUSTOMER_ID) as RESULT
  from    HAVE
  group by MARKET_AREA
  union all
  select  MARKET_REGION as COL1,
          count(CUSTOMER_ID) as RESULT
  from    HAVE
  group by MARKET_REGION;
quit;

&lt;/PRE&gt;
&lt;P&gt;Note how I put the test data in a datastep, ples use that methd in future to convey structure as well as data.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Aug 2017 10:45:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Two-Way-Proc-Report/m-p/390872#M66174</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-08-25T10:45:58Z</dc:date>
    </item>
    <item>
      <title>Re: Two Way Proc Report</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Two-Way-Proc-Report/m-p/390873#M66175</link>
      <description>&lt;P&gt;Thank you for your suggestion, I tried the solution but now It is coming as all the market_areq together and Regions togethere.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need Market area Followed by the corresponding regions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Fri, 25 Aug 2017 10:51:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Two-Way-Proc-Report/m-p/390873#M66175</guid>
      <dc:creator>Gangi</dc:creator>
      <dc:date>2017-08-25T10:51:43Z</dc:date>
    </item>
    <item>
      <title>Re: Two Way Proc Report</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Two-Way-Proc-Report/m-p/390876#M66176</link>
      <description>&lt;P&gt;Yes, then you need to apply sorts to the data:&lt;/P&gt;
&lt;PRE&gt;data have;&lt;BR /&gt; input market_area $ market_region $ customer_id;&lt;BR /&gt;datalines; &lt;BR /&gt;east A 12&lt;BR /&gt;east A 13&lt;BR /&gt;east B 10&lt;BR /&gt;east C 17&lt;BR /&gt;west A 12&lt;BR /&gt;west A 13&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt; create table WANT as&lt;BR /&gt; select COALESCE(MARKET_REGION,MARKET_AREA) as COL1,&lt;BR /&gt;        RESULT &lt;BR /&gt; from   (select MARKET_AREA,&lt;BR /&gt;                "" as MARKET_REGION,&lt;BR /&gt;                count(CUSTOMER_ID) as RESULT&lt;BR /&gt;         from HAVE&lt;BR /&gt;         group by MARKET_AREA&lt;BR /&gt;         union all&lt;BR /&gt;         select MARKET_AREA,&lt;BR /&gt;                MARKET_REGION,&lt;BR /&gt;                count(CUSTOMER_ID) as RESULT&lt;BR /&gt;         from HAVE&lt;BR /&gt;         group by MARKET_AREA,&lt;BR /&gt;                  MARKET_REGION)&lt;BR /&gt; order by MARKET_AREA,MARKET_REGION;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Aug 2017 11:08:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Two-Way-Proc-Report/m-p/390876#M66176</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-08-25T11:08:20Z</dc:date>
    </item>
    <item>
      <title>Re: Two Way Proc Report</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Two-Way-Proc-Report/m-p/390880#M66177</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use Proc REPORT to get what you want. For this you do need two additional computed columns.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the compute block for the _DUMMY column, we have the logic to fill the column M_NAME with the appropriate content.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have a look below. If there is not nesting between market area and market region, you could also use Proc TABULATE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input market_area $ market_region $ customer_id;
datalines;
east A 12
east A 13
east B 10
east C 17
west D 12
west E 15
west F 18
;

proc report data=have;
  column market_area market_region m_name customer_id _dummy;
  define market_area / group noprint;
  define market_region / group noprint;
  define m_name / computed ;
  define customer_id / analysis n;
  define _dummy / computed noprint;

  break before market_area / summarize;

  rbreak after / summarize;
  compute m_name / char length=32;
  endcomp;

  compute _dummy / char length=32;
    _dummy = _break_;
    if lowcase(_break_) = "market_area" then do;
      m_name = market_area;
    end;
    if _break_ = " " then do;
      m_name = market_region;
    end;
    if _break_ = "_RBREAK_" then do;
      m_name = "Total";
    end;
  endcomp;
run;

proc tabulate data=have;
  class market_area market_region;
  table
    market_area="Area"
    market_region=" "
    all
    ,
    n
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 25 Aug 2017 12:05:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Two-Way-Proc-Report/m-p/390880#M66177</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2017-08-25T12:05:08Z</dc:date>
    </item>
    <item>
      <title>Re: Two Way Proc Report</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Two-Way-Proc-Report/m-p/390890#M66181</link>
      <description>&lt;PRE&gt;
How about this one?



data have;
  input market_area $ market_region $ customer_id;
datalines; 
east A 12
east A 13
east B 10
east C 17
;
run;
proc report data=have nowd;
column  market_area  market_region  n;
define market_area/group noprint;
define market_region/group;
define n/'count';
compute before market_area;
 market_region=market_area;
endcomp;
break before market_area/summarize;
run;



&lt;/PRE&gt;</description>
      <pubDate>Fri, 25 Aug 2017 12:52:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Two-Way-Proc-Report/m-p/390890#M66181</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-08-25T12:52:51Z</dc:date>
    </item>
    <item>
      <title>Re: Two Way Proc Report</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Two-Way-Proc-Report/m-p/390891#M66182</link>
      <description>&lt;P&gt;Thank &amp;nbsp;you very much for the Answer.. It is working as expected.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Aug 2017 12:59:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Two-Way-Proc-Report/m-p/390891#M66182</guid>
      <dc:creator>Gangi</dc:creator>
      <dc:date>2017-08-25T12:59:09Z</dc:date>
    </item>
  </channel>
</rss>

