<?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: How to control the order in proc report in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-control-the-order-in-proc-report/m-p/883296#M82816</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/259318"&gt;@Coooooo_Lee&lt;/a&gt;,&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/259318"&gt;@Coooooo_Lee&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Why&amp;nbsp; order in the result is different from the dataset?&lt;/P&gt;
&lt;P&gt;I've set each order option as oder=data.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This is because ORDER=DATA looks at the &lt;EM&gt;entire&lt;/EM&gt; dataset. Since C4 values "C3D1", "C5D1" and "C7D1" occur&amp;nbsp;&lt;EM&gt;before&lt;/EM&gt; "SCR" in the data (for a different C2 value, though, but this doesn't matter), this order is used consistently throughout the report.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Basically the same issue was discussed earlier this year in the thread "&lt;A href="https://communities.sas.com/t5/SAS-Programming/PROC-REPORT-order-data-within-levels-of-grouping-variable/m-p/864994" target="_blank" rel="noopener"&gt;PROC REPORT order=data within levels of grouping variable&lt;/A&gt;". The solution provided there should work for your data, too.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit:&lt;/P&gt;
&lt;P&gt;Here's how you could implement that solution:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set test;
by c1-c4 notsorted;
realorder+first.c4;
run;

proc report data=want headline headskip split='#' spacing=1 missing;
column c1-c3 realorder c4 c5;
define c1 /  'C1'  order order=data;
define c2 /  'C2'  order order=data;
define c3 /  'C3'  order order=data;
define realorder / order noprint;
define c4 /  'C4'  order order=data;
define c5 /  'C5';
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 03 Jul 2023 10:36:42 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2023-07-03T10:36:42Z</dc:date>
    <item>
      <title>How to control the order in proc report</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-control-the-order-in-proc-report/m-p/883280#M82815</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks very much if anyone can help to resolve below issue.&lt;/P&gt;
&lt;P&gt;I've got a problem regarding the proc report. Below are the test code and result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  input c1 $
	    c2 $
	    c3 $
	    c4 $
	    c5 $;
datalines;
A 1001 70/M C3D1 1
A 1001 70/M C3D1 2
A 1001 70/M C5D1 1
A 1001 70/M C5D1 2
A 1001 70/M C7D1 1
A 1001 70/M C7D1 2
A 1002 68/F SCR  1
A 1002 68/F SCR  2
A 1002 68/F C3D1 1
A 1002 68/F C3D1 2
A 1002 68/F C5D1 1
A 1002 68/F C5D1 2
;
RUN;



PROC REPORT DATA=TEST NOWD HEADLINE HEADSKIP SPLIT='#' SPACING=1 MISSING ;
column c1 c2 c3  c4  c5;  
 define c1 /  'C1' order order=data;

  define c2 /  'C2' order order=data ;

  define c3 /  'C3' order order=data;

  define c4 /  'C4'  order order=data ;

  define c5 /  'C5';
RUN;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why&amp;nbsp; order in the result is different from the dataset?&lt;/P&gt;
&lt;P&gt;I've set each order option as oder=data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the 1002, the records when C4="SCR"&amp;nbsp; go after the C3D1, how can I ouput the order the same as datasets?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jul 2023 03:56:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-control-the-order-in-proc-report/m-p/883280#M82815</guid>
      <dc:creator>Coooooo_Lee</dc:creator>
      <dc:date>2023-07-03T03:56:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to control the order in proc report</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-control-the-order-in-proc-report/m-p/883296#M82816</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/259318"&gt;@Coooooo_Lee&lt;/a&gt;,&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/259318"&gt;@Coooooo_Lee&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Why&amp;nbsp; order in the result is different from the dataset?&lt;/P&gt;
&lt;P&gt;I've set each order option as oder=data.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This is because ORDER=DATA looks at the &lt;EM&gt;entire&lt;/EM&gt; dataset. Since C4 values "C3D1", "C5D1" and "C7D1" occur&amp;nbsp;&lt;EM&gt;before&lt;/EM&gt; "SCR" in the data (for a different C2 value, though, but this doesn't matter), this order is used consistently throughout the report.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Basically the same issue was discussed earlier this year in the thread "&lt;A href="https://communities.sas.com/t5/SAS-Programming/PROC-REPORT-order-data-within-levels-of-grouping-variable/m-p/864994" target="_blank" rel="noopener"&gt;PROC REPORT order=data within levels of grouping variable&lt;/A&gt;". The solution provided there should work for your data, too.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit:&lt;/P&gt;
&lt;P&gt;Here's how you could implement that solution:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set test;
by c1-c4 notsorted;
realorder+first.c4;
run;

proc report data=want headline headskip split='#' spacing=1 missing;
column c1-c3 realorder c4 c5;
define c1 /  'C1'  order order=data;
define c2 /  'C2'  order order=data;
define c3 /  'C3'  order order=data;
define realorder / order noprint;
define c4 /  'C4'  order order=data;
define c5 /  'C5';
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 03 Jul 2023 10:36:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-control-the-order-in-proc-report/m-p/883296#M82816</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2023-07-03T10:36:42Z</dc:date>
    </item>
  </channel>
</rss>

