<?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 How do I make sure proc report with across writes observations to the same row? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-make-sure-proc-report-with-across-writes-observations/m-p/884768#M349557</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I use the following code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;ods excel file="[path].xlsx" options(sheet_interval='bygroup'
                    sheet_name="#byval(bladnamn)");
PROC REPORT data=export;
by bladnamn;
column bladnamn kon, (variabel_cat_varde alder_grupp andel CI_lower CI_upper lillan);
/* define variabelnamn / order order=internal;*/
/*define order / order order=internal;*/
/*define variabel / order order=internal;*/
define bladnamn / noprint;
define variabel_cat_varde / display;
define alder_grupp / display;
define andel / analysis;
define CI_lower / analysis;
define CI_upper / analysis;
define lillan / analysis;
DEFINE kon / ACROSS ORDER=INTERNAL; 



run;

ods excel close;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;and get the following output:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Namnlös.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/85769i3DBC45BA677D9B50/image-size/large?v=v2&amp;amp;px=999" role="button" title="Namnlös.png" alt="Namnlös.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;That is to say, values for the different values of my gender variable (kon) seem to appear on different rows. Naturally I don't want this to happen. Values belonging to the same group should appear on the same row, regardless of gender.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I make this happen?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 14 Jul 2023 13:33:13 GMT</pubDate>
    <dc:creator>Syntas_error</dc:creator>
    <dc:date>2023-07-14T13:33:13Z</dc:date>
    <item>
      <title>How do I make sure proc report with across writes observations to the same row?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-make-sure-proc-report-with-across-writes-observations/m-p/884768#M349557</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I use the following code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;ods excel file="[path].xlsx" options(sheet_interval='bygroup'
                    sheet_name="#byval(bladnamn)");
PROC REPORT data=export;
by bladnamn;
column bladnamn kon, (variabel_cat_varde alder_grupp andel CI_lower CI_upper lillan);
/* define variabelnamn / order order=internal;*/
/*define order / order order=internal;*/
/*define variabel / order order=internal;*/
define bladnamn / noprint;
define variabel_cat_varde / display;
define alder_grupp / display;
define andel / analysis;
define CI_lower / analysis;
define CI_upper / analysis;
define lillan / analysis;
DEFINE kon / ACROSS ORDER=INTERNAL; 



run;

ods excel close;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;and get the following output:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Namnlös.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/85769i3DBC45BA677D9B50/image-size/large?v=v2&amp;amp;px=999" role="button" title="Namnlös.png" alt="Namnlös.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;That is to say, values for the different values of my gender variable (kon) seem to appear on different rows. Naturally I don't want this to happen. Values belonging to the same group should appear on the same row, regardless of gender.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I make this happen?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jul 2023 13:33:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-make-sure-proc-report-with-across-writes-observations/m-p/884768#M349557</guid>
      <dc:creator>Syntas_error</dc:creator>
      <dc:date>2023-07-14T13:33:13Z</dc:date>
    </item>
    <item>
      <title>Re: How do I make sure proc report with across writes observations to the same row?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-make-sure-proc-report-with-across-writes-observations/m-p/884781#M349561</link>
      <description>&lt;P&gt;You need a column defined as GROUP which forces multiple values of kon into the same row.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jul 2023 12:21:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-make-sure-proc-report-with-across-writes-observations/m-p/884781#M349561</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-07-14T12:21:43Z</dc:date>
    </item>
    <item>
      <title>Re: How do I make sure proc report with across writes observations to the same row?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-make-sure-proc-report-with-across-writes-observations/m-p/884783#M349563</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*
Here is an example .
You need a ID variable.
*/
data have;
 set sashelp.heart(obs=20);
 keep status sex ageatstart weight height;
run;
proc sort data=have;by status sex;run;
data have;
 set have;
 by status sex;
 if first.sex then id=0;
 id+1;
run;
proc report data=have nowd;
by status;
column id sex,(ageatstart weight height);
define id/group noprint;
define sex/across '';
define ageatstart/display;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 14 Jul 2023 12:24:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-make-sure-proc-report-with-across-writes-observations/m-p/884783#M349563</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-07-14T12:24:23Z</dc:date>
    </item>
    <item>
      <title>Re: How do I make sure proc report with across writes observations to the same row?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-make-sure-proc-report-with-across-writes-observations/m-p/884787#M349567</link>
      <description>&lt;P&gt;Something like this, or should I avoid using multiple group variables?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;PROC REPORT data=export;
by bladnamn;
column bladnamn variabel_cat_varde alder_grupp (kon,(andel CI_lower CI_upper lillan));
define bladnamn / noprint;
define variabel_cat_varde / group;
define alder_grupp / group;
define andel / mean;
define CI_lower / mean;
define CI_upper / mean;
define lillan / mean;
DEFINE kon / ACROSS ORDER=INTERNAL;


run;

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jul 2023 13:05:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-make-sure-proc-report-with-across-writes-observations/m-p/884787#M349567</guid>
      <dc:creator>Syntas_error</dc:creator>
      <dc:date>2023-07-14T13:05:17Z</dc:date>
    </item>
    <item>
      <title>Re: How do I make sure proc report with across writes observations to the same row?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-make-sure-proc-report-with-across-writes-observations/m-p/884789#M349569</link>
      <description>&lt;P&gt;You can define as many variables as GROUP as you like; it has to make sense for your intended logic.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jul 2023 13:08:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-make-sure-proc-report-with-across-writes-observations/m-p/884789#M349569</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-07-14T13:08:48Z</dc:date>
    </item>
    <item>
      <title>Re: How do I make sure proc report with across writes observations to the same row?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-make-sure-proc-report-with-across-writes-observations/m-p/884790#M349570</link>
      <description>&lt;P&gt;That may be true, but I posted that snippet (inspired by this page &lt;A href="https://support.sas.com/resources/papers/proceedings14/SAS388-2014.pdf" target="_blank"&gt;https://support.sas.com/resources/papers/proceedings14/SAS388-2014.pdf&lt;/A&gt;) mostly because it didn't work (the results are still written to different rows according to sex) and I'm trying to wrap my head around why.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I asked my manager about posting a repex and hopefully it shouldn't be a problem.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jul 2023 13:11:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-make-sure-proc-report-with-across-writes-observations/m-p/884790#M349570</guid>
      <dc:creator>Syntas_error</dc:creator>
      <dc:date>2023-07-14T13:11:56Z</dc:date>
    </item>
    <item>
      <title>Re: How do I make sure proc report with across writes observations to the same row?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-make-sure-proc-report-with-across-writes-observations/m-p/884793#M349572</link>
      <description>Okay, uploaded data for one of the sheets, should be enough I hope. On that note, is there a preferred way to upload repredocible examples for sas?</description>
      <pubDate>Fri, 14 Jul 2023 13:34:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-make-sure-proc-report-with-across-writes-observations/m-p/884793#M349572</guid>
      <dc:creator>Syntas_error</dc:creator>
      <dc:date>2023-07-14T13:34:53Z</dc:date>
    </item>
    <item>
      <title>Re: How do I make sure proc report with across writes observations to the same row?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-make-sure-proc-report-with-across-writes-observations/m-p/884798#M349573</link>
      <description>I'm sorry but I have a hard time using code I don't understand. What does ID do exactly? And would I be able to use this method with two additional character variables besides the gender variable used for ACROSS?</description>
      <pubDate>Fri, 14 Jul 2023 13:37:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-make-sure-proc-report-with-across-writes-observations/m-p/884798#M349573</guid>
      <dc:creator>Syntas_error</dc:creator>
      <dc:date>2023-07-14T13:37:46Z</dc:date>
    </item>
    <item>
      <title>Re: How do I make sure proc report with across writes observations to the same row?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-make-sure-proc-report-with-across-writes-observations/m-p/884804#M349576</link>
      <description>&lt;P&gt;Try letting PROC REPORT know that you want one row per value of BLADNAMN.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;define bladnamn / group noprint;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 14 Jul 2023 14:00:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-make-sure-proc-report-with-across-writes-observations/m-p/884804#M349576</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-07-14T14:00:40Z</dc:date>
    </item>
    <item>
      <title>Re: How do I make sure proc report with across writes observations to the same row?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-make-sure-proc-report-with-across-writes-observations/m-p/884805#M349577</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/254512"&gt;@Syntas_error&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Okay, uploaded data for one of the sheets, should be enough I hope. On that note, is there a preferred way to upload repredocible examples for sas?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Just share the data as an actual data step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data class ;
  input name :$8. sex :$1. age height weight ;
cards;
Alfred M 14 69 112.5
Alice F 13 56.5 84
Barbara F 13 65.3 98
Carol F 14 62.8 102.5
Henry M 14 63.5 102.5
James M 12 57.3 83
Jane F 12 59.8 84.5
Janet F 15 62.5 112.5
Jeffrey M 13 62.5 84
John M 12 59 99.5
Joyce F 11 51.3 50.5
Judy F 14 64.3 90
Louise F 12 56.3 77
Mary F 15 66.5 112
Philip M 16 72 150
Robert M 12 64.8 128
Ronald M 15 67 133
Thomas M 11 57.5 85
William M 15 66.5 112
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which is trivial to create from an existing dataset.&amp;nbsp; Just use a data step to dump the lines of data to the SAS log.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set sashelp.class ;
  put name sex age height weight;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can copy and paste them back into the program editor.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your data is more complicated there a macros that can create the data step for you.&amp;nbsp; Look at&amp;nbsp;&lt;A href="https://github.com/sasutils/macros/blob/master/ds2post.sas" target="_blank"&gt;https://github.com/sasutils/macros/blob/master/ds2post.sas&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jul 2023 14:08:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-make-sure-proc-report-with-across-writes-observations/m-p/884805#M349577</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-07-14T14:08:42Z</dc:date>
    </item>
    <item>
      <title>Re: How do I make sure proc report with across writes observations to the same row?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-make-sure-proc-report-with-across-writes-observations/m-p/884807#M349578</link>
      <description>Thanks, that worked!&lt;BR /&gt;&lt;BR /&gt;The order is a bit distorted (I guess the observations get shuffled arund during the pivoting process?) but strictly speaking that's another question &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Fri, 14 Jul 2023 14:07:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-make-sure-proc-report-with-across-writes-observations/m-p/884807#M349578</guid>
      <dc:creator>Syntas_error</dc:creator>
      <dc:date>2023-07-14T14:07:33Z</dc:date>
    </item>
    <item>
      <title>Re: How do I make sure proc report with across writes observations to the same row?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-make-sure-proc-report-with-across-writes-observations/m-p/884809#M349579</link>
      <description>&lt;P&gt;You told it to order the columns based on the stored value of KON (not the displayed values).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DEFINE kon / ACROSS ORDER=INTERNAL; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 14 Jul 2023 14:12:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-make-sure-proc-report-with-across-writes-observations/m-p/884809#M349579</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-07-14T14:12:12Z</dc:date>
    </item>
    <item>
      <title>Re: How do I make sure proc report with across writes observations to the same row?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-make-sure-proc-report-with-across-writes-observations/m-p/884812#M349580</link>
      <description>Sure, but that's for telling SAS the order in which the pivoted columns should be presented ?&lt;BR /&gt;&lt;BR /&gt;(so "1!" to the far left, "2" in the middle and "3" to the far right)&lt;BR /&gt;&lt;BR /&gt;That I have no problem with, only that the order of rows seems to have changed from the order in the original data.</description>
      <pubDate>Fri, 14 Jul 2023 14:21:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-make-sure-proc-report-with-across-writes-observations/m-p/884812#M349580</guid>
      <dc:creator>Syntas_error</dc:creator>
      <dc:date>2023-07-14T14:21:32Z</dc:date>
    </item>
    <item>
      <title>Re: How do I make sure proc report with across writes observations to the same row?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-make-sure-proc-report-with-across-writes-observations/m-p/884813#M349581</link>
      <description>&lt;P&gt;Then tell PROC REPORT how to order the grouping variable.&lt;/P&gt;
&lt;P&gt;To leave them the same then try ORDER=DATA .&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jul 2023 14:28:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-make-sure-proc-report-with-across-writes-observations/m-p/884813#M349581</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-07-14T14:28:33Z</dc:date>
    </item>
  </channel>
</rss>

