<?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: Order changed for across variable in proc report in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Order-changed-for-across-variable-in-proc-report/m-p/603621#M174896</link>
    <description>&lt;P&gt;Hi Cynthia,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It looks great! But can I know how did you reorganized the data? It seems for data with&amp;nbsp;y=C, the order of grp and z is different with those with y=A or y=B.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
    <pubDate>Tue, 12 Nov 2019 16:36:10 GMT</pubDate>
    <dc:creator>KK13680</dc:creator>
    <dc:date>2019-11-12T16:36:10Z</dc:date>
    <item>
      <title>Order changed for across variable in proc report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Order-changed-for-across-variable-in-proc-report/m-p/602937#M174628</link>
      <description>&lt;P&gt;I am trying to create the table using proc report but the order seems changed but I have no idea why and how to solve it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here are my codes:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
infile datalines dlm=",";
informat x $10.
         y $20.
         z $20.
		 group $20.
         description $20.;
input x $ y $ z $ group $  description $;
datalines;
X,A,Total (N=2000),Total,709 (35.5 %)
X,B,Total (N=2000),Total,190 (9.5 %)
X,C,Total (N=2000),Total,2 (0.1 %)
X,A,0 (N=57),Total,23 (40.4 %)
X,B,0 (N=57),Total,4 (7 %)
X,C,0 (N=57),Total,0 (0 %)
X,A,I (N=393),Total,155 (39.4 %)
X,B,I (N=393),Total,29 (7.4 %)
X,C,I (N=393),Total,0 (0 %)
X,A,II (N=551),Total,188 (34.1 %)
X,B,II (N=551),Total,52 (9.4 %)
X,C,II (N=551),Total,0 (0 %)
X,A,Total (N=1520),0,537 (35.3 %)
X,B,Total (N=1520),0,138 (9.1 %)
X,C,Total (N=1520),0,2 (0.1 %)
X,A,0 (N=57),0,23 (40.4 %)
X,B,0 (N=57),0,4 (7 %)
X,C,0 (N=57),0,0 (0 %)
X,A,I (N=349),0,138 (39.5 %)
X,B,I (N=349),0,25 (7.2 %)
X,C,I (N=349),0,0 (0 %)
X,A,II (N=424),0,145 (34.2 %)
X,B,II (N=424),0,42 (9.9 %)
X,C,II (N=424),0,0 (0 %)
X,A,Total (N=480),1,172 (35.8 %)
X,B,Total (N=480),1,52 (10.8 %)
X,C,Total (N=480),1,0 (0%)
X,A,I (N=44),1,17 (38.6 %)
X,B,I (N=44),1,4 (9.1 %)
X,C,I (N=44),1,0 (0%)
X,A,II (N=127),1,43 (33.9 %)
X,B,II (N=127),1,10 (7.9 %)
X,C,II (N=127),1,0 (0%)
;
run;

proc report data=test missing;
column x  y  group, (z, description);
define x/' ' group order=data;
define y/' ' group order=data;
define z/' ' order=data across ;
define group/' ' order=data across nozero;
define description/ ' ' group ;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And the output looks like&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="11.PNG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/33796i32402765DEA91F4D/image-size/large?v=v2&amp;amp;px=999" role="button" title="11.PNG" alt="11.PNG" /&gt;&lt;/span&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I would like it to be the following where the total one is ahead of the 0 term.&lt;/P&gt;&lt;DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="22.PNG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/33797i4FB69A11F40AC299/image-size/large?v=v2&amp;amp;px=999" role="button" title="22.PNG" alt="22.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any solution for solving it?&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 08 Nov 2019 23:54:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Order-changed-for-across-variable-in-proc-report/m-p/602937#M174628</guid>
      <dc:creator>KK13680</dc:creator>
      <dc:date>2019-11-08T23:54:55Z</dc:date>
    </item>
    <item>
      <title>Re: Order changed for across variable in proc report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Order-changed-for-across-variable-in-proc-report/m-p/602996#M174655</link>
      <description>&lt;P&gt;Hi:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; If you want to use ORDER=DATA, then the data in the DATALINES has to be in the correct order. I restructured your DATALINES a bit and added a COL_ORD variable, so the pattern of the data was a bit more obvious. If you want the Total column to ALWAYS appear before the 0 column, then the data has to be organized that way. Here's what I generated with the changed data and slightly changed code:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="report_across_dummyvar.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/33807i59E5A769E3767908/image-size/large?v=v2&amp;amp;px=999" role="button" title="report_across_dummyvar.png" alt="report_across_dummyvar.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Also, I changed the code in these ways:&lt;/P&gt;
&lt;P&gt;1) I never name a variable "GROUP" (or ORDER or COMPUTED, since those are PROC REPORT usages)-- so I changed it to GRP&lt;/P&gt;
&lt;P&gt;2) I took off MISSING and NOZERO and used NOCOMPLETECOLS instead&lt;/P&gt;
&lt;P&gt;3) a better way to put a character string under an ACROSS item is to put one numeric variable at the end of the report row (in this case, DUMMY) and then use NOPRINT so the dummy values are not visible--but, that way, PROC REPORT has a numeric value to collapse for the GROUP items.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps,&lt;/P&gt;
&lt;P&gt;Cynthia&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  length x $10 y $20 grp $20 z $20 description $20;
  infile datalines dlm="," dsd;
 input x $ y $ grp $ z $ description $ col_ord;
datalines;
X,A,Total,Total (N=2000),709 (35.5 %),1.1
X,A,0,Total (N=1520),537 (35.3 %),2.1
X,A,1,Total (N=480),172 (35.8 %),3.1
X,A,Total,0 (N=57),23 (40.4 %),1.2
X,A,0,0 (N=57),23 (40.4 %),2.2
X,A,1,I (N=44),17 (38.6 %),3.2
X,A,Total,I (N=393),155 (39.4 %),1.3
X,A,0,I (N=349),138 (39.5 %),2.3
X,A,1,II (N=127),43 (33.9 %),3.3
X,A,Total,II (N=551),188 (34.1 %),1.4
X,A,0,II (N=424),145 (34.2 %),2.4
X,B,Total,Total (N=2000),190 (9.5 %),1.1
X,B,0,Total (N=1520),138 (9.1 %),2.1
X,B,1,Total (N=480),52 (10.8 %),3.1
X,B,Total,0 (N=57),4 (7 %),1.2
X,B,0,0 (N=57),4 (7 %),2.2
X,B,1,I (N=44),4 (9.1 %),3.2
X,B,Total,I (N=393),29 (7.4 %),1.3
X,B,0,I (N=349),25 (7.2 %),2.3
X,B,1,II (N=127),10 (7.9 %),3.3
X,B,Total,II (N=551),52 (9.4 %),1.4
X,B,0,II (N=424),42 (9.9 %),2.4
X,C,Total,Total (N=2000),2 (0.1 %),1.1
X,C,Total,0 (N=57),0 (0 %),1.2
X,C,Total,I (N=393),0 (0 %),1.3
X,C,Total,II (N=551),0 (0 %),1.4
X,C,0,Total (N=1520),2 (0.1 %),2.1
X,C,0,0 (N=57),0 (0 %),2.2
X,C,0,I (N=349),0 (0 %),2.3
X,C,0,II (N=424),0 (0 %),2.4
X,C,1,Total (N=480),0 (0%),3.1
X,C,1,I (N=44),0 (0%),3.2
X,C,1,II (N=127),0 (0%),3.3
;
run;

title;
proc report data=test nocompletecols;
column x  y  grp,(z, description) dummy;
define x/' ' group  ;
define y/' ' group  ;
define grp/' '  across order=data ;
define z/' '   across order=data;
define description/ ' ' display;
define dummy / computed ' ' noprint;
compute dummy;
  dummy=1;
endcomp;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 09 Nov 2019 17:00:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Order-changed-for-across-variable-in-proc-report/m-p/602996#M174655</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2019-11-09T17:00:26Z</dc:date>
    </item>
    <item>
      <title>Re: Order changed for across variable in proc report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Order-changed-for-across-variable-in-proc-report/m-p/603621#M174896</link>
      <description>&lt;P&gt;Hi Cynthia,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It looks great! But can I know how did you reorganized the data? It seems for data with&amp;nbsp;y=C, the order of grp and z is different with those with y=A or y=B.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 12 Nov 2019 16:36:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Order-changed-for-across-variable-in-proc-report/m-p/603621#M174896</guid>
      <dc:creator>KK13680</dc:creator>
      <dc:date>2019-11-12T16:36:10Z</dc:date>
    </item>
    <item>
      <title>Re: Order changed for across variable in proc report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Order-changed-for-across-variable-in-proc-report/m-p/603670#M174906</link>
      <description>&lt;P&gt;Yes, that was my mistake in copy and paste, but as you saw, it did not make a difference. Once the "pattern" was set for y=A, PROC REPORT would use that pattern for y=B and y=C -- although in my mind, it would be far better from a maintenance standpoint for the datalines to be consistent.&lt;BR /&gt;Sorry, here's the revised code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test2;
  length x $10 y $20 grp $20 z $20 description $20;
  infile datalines dlm="," dsd;
 input x $ y $ grp $ z $ description $ col_ord;
datalines;
X,A,Total,Total (N=2000),709 (35.5 %),1.1
X,A,0,Total (N=1520),537 (35.3 %),2.1
X,A,1,Total (N=480),172 (35.8 %),3.1
X,A,Total,0 (N=57),23 (40.4 %),1.2
X,A,0,0 (N=57),23 (40.4 %),2.2
X,A,1,I (N=44),17 (38.6 %),3.2
X,A,Total,I (N=393),155 (39.4 %),1.3
X,A,0,I (N=349),138 (39.5 %),2.3
X,A,1,II (N=127),43 (33.9 %),3.3
X,A,Total,II (N=551),188 (34.1 %),1.4
X,A,0,II (N=424),145 (34.2 %),2.4
X,B,Total,Total (N=2000),190 (9.5 %),1.1
X,B,0,Total (N=1520),138 (9.1 %),2.1
X,B,1,Total (N=480),52 (10.8 %),3.1
X,B,Total,0 (N=57),4 (7 %),1.2
X,B,0,0 (N=57),4 (7 %),2.2
X,B,1,I (N=44),4 (9.1 %),3.2
X,B,Total,I (N=393),29 (7.4 %),1.3
X,B,0,I (N=349),25 (7.2 %),2.3
X,B,1,II (N=127),10 (7.9 %),3.3
X,B,Total,II (N=551),52 (9.4 %),1.4
X,B,0,II (N=424),42 (9.9 %),2.4
X,C,Total,Total (N=2000),2 (0.1 %),1.1
X,C,0,Total (N=1520),2 (0.1 %),2.1
X,C,1,Total (N=480),0 (0%),3.1
X,C,Total,0 (N=57),0 (0 %),1.2
X,C,0,0 (N=57),0 (0 %),2.2
X,C,1,I (N=44),0 (0%),3.2
X,C,Total,I (N=393),0 (0 %),1.3
X,C,0,I (N=349),0 (0 %),2.3
X,C,1,II (N=127),0 (0%),3.3
X,C,Total,II (N=551),0 (0 %),1.4
X,C,0,II (N=424),0 (0 %),2.4
;
run;

title;
proc report data=test2 nocompletecols;
column x  y  grp,(z, description) dummy;
define x/' ' group  ;
define y/' ' group  ;
define grp/' '  across order=data ;
define z/' '   across order=data;
define description/ ' ' display;
define dummy / computed ' ' noprint;
compute dummy;
  dummy=1;
endcomp;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;and as you can see the output is the same. FYI -- here's how I patterned the data -- so that the x.1 columns appeared first, followed by the x.2 columns, then the x.3 columns then the x.4 columns.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="same_output.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/33921iC3BAD3C4DC42ADE4/image-size/large?v=v2&amp;amp;px=999" role="button" title="same_output.png" alt="same_output.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Cynthia&lt;/P&gt;</description>
      <pubDate>Tue, 12 Nov 2019 19:01:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Order-changed-for-across-variable-in-proc-report/m-p/603670#M174906</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2019-11-12T19:01:19Z</dc:date>
    </item>
    <item>
      <title>Re: Order changed for across variable in proc report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Order-changed-for-across-variable-in-proc-report/m-p/603674#M174908</link>
      <description>Thank you very much. I really appreciate your help!</description>
      <pubDate>Tue, 12 Nov 2019 18:59:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Order-changed-for-across-variable-in-proc-report/m-p/603674#M174908</guid>
      <dc:creator>KK13680</dc:creator>
      <dc:date>2019-11-12T18:59:25Z</dc:date>
    </item>
  </channel>
</rss>

