<?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 swap sex type in proc ttest, so that males are shown before females in the print out tabl in SAS Software for Learning Community</title>
    <link>https://communities.sas.com/t5/SAS-Software-for-Learning/How-to-swap-sex-type-in-proc-ttest-so-that-males-are-shown/m-p/868627#M1073</link>
    <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/441601"&gt;@TDechamp&lt;/a&gt;&amp;nbsp;and welcome to the SAS Support Communities!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use the &lt;A href="https://documentation.sas.com/doc/en/statug/15.3/statug_ttest_syntax01.htm#statug.ttest.tteprocorder" target="_blank" rel="noopener"&gt;ORDER= option&lt;/A&gt; of the PROC TTEST statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc ttest data=sashelp.class order=data;
class sex;
var height;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The output displays males first because the first non-missing value of variable SEX in the dataset is 'M'. If that weren't the case, a PROC SORT step as shown below could create a suitably sorted input dataset for PROC TTEST:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=sashelp.class out=want;
by descending sex;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that in other datasets (perhaps in yours) variable SEX might be numeric with an associated format, e.g., 1=male, 2=female. In this case &lt;FONT face="courier new,courier"&gt;order=internal&lt;/FONT&gt; could be used without sorting.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: In SASHELP.HEART, as shown in your second post, SEX is a character variable and 'Female' happens to occur first. So, use PROC SORT as above to get 'Male' values to the top in &lt;SPAN&gt;EXAMPLE.HEART.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 07 Apr 2023 15:53:00 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2023-04-07T15:53:00Z</dc:date>
    <item>
      <title>How to swap sex type in proc ttest, so that males are shown before females in the print out table</title>
      <link>https://communities.sas.com/t5/SAS-Software-for-Learning/How-to-swap-sex-type-in-proc-ttest-so-that-males-are-shown/m-p/868622#M1071</link>
      <description>&lt;P&gt;Hello, I'm trying to find a way to swap the place of the two mean groups, Males and Females, in my data set so that when I run a proc ttest on the data set males are displayed first and then females so then my confidence interval for the difference between two means is (Males - Females) and not (Females - Males).&amp;nbsp; I've tried sorting by sex and class sex too, but I cannot get the Male group to come first in the output table.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Apr 2023 15:17:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Software-for-Learning/How-to-swap-sex-type-in-proc-ttest-so-that-males-are-shown/m-p/868622#M1071</guid>
      <dc:creator>TDechamp</dc:creator>
      <dc:date>2023-04-07T15:17:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to swap sex type in proc ttest, so that males are shown before females in the print out tabl</title>
      <link>https://communities.sas.com/t5/SAS-Software-for-Learning/How-to-swap-sex-type-in-proc-ttest-so-that-males-are-shown/m-p/868623#M1072</link>
      <description>&lt;P&gt;The current code I've been trying is:&lt;/P&gt;&lt;P&gt;Data Example.heart; set sashelp.heart;&lt;/P&gt;&lt;P&gt;proc ttest data=example.heart alpha=0.05 order=data;&lt;BR /&gt;class sex;&lt;BR /&gt;var weight;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Apr 2023 15:30:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Software-for-Learning/How-to-swap-sex-type-in-proc-ttest-so-that-males-are-shown/m-p/868623#M1072</guid>
      <dc:creator>TDechamp</dc:creator>
      <dc:date>2023-04-07T15:30:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to swap sex type in proc ttest, so that males are shown before females in the print out tabl</title>
      <link>https://communities.sas.com/t5/SAS-Software-for-Learning/How-to-swap-sex-type-in-proc-ttest-so-that-males-are-shown/m-p/868627#M1073</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/441601"&gt;@TDechamp&lt;/a&gt;&amp;nbsp;and welcome to the SAS Support Communities!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use the &lt;A href="https://documentation.sas.com/doc/en/statug/15.3/statug_ttest_syntax01.htm#statug.ttest.tteprocorder" target="_blank" rel="noopener"&gt;ORDER= option&lt;/A&gt; of the PROC TTEST statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc ttest data=sashelp.class order=data;
class sex;
var height;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The output displays males first because the first non-missing value of variable SEX in the dataset is 'M'. If that weren't the case, a PROC SORT step as shown below could create a suitably sorted input dataset for PROC TTEST:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=sashelp.class out=want;
by descending sex;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that in other datasets (perhaps in yours) variable SEX might be numeric with an associated format, e.g., 1=male, 2=female. In this case &lt;FONT face="courier new,courier"&gt;order=internal&lt;/FONT&gt; could be used without sorting.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: In SASHELP.HEART, as shown in your second post, SEX is a character variable and 'Female' happens to occur first. So, use PROC SORT as above to get 'Male' values to the top in &lt;SPAN&gt;EXAMPLE.HEART.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Apr 2023 15:53:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Software-for-Learning/How-to-swap-sex-type-in-proc-ttest-so-that-males-are-shown/m-p/868627#M1073</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2023-04-07T15:53:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to swap sex type in proc ttest, so that males are shown before females in the print out tabl</title>
      <link>https://communities.sas.com/t5/SAS-Software-for-Learning/How-to-swap-sex-type-in-proc-ttest-so-that-males-are-shown/m-p/868636#M1074</link>
      <description>&lt;P&gt;Another option if you can't get an ORDER=Data to work is to assign a format that changes the order and use Order=Formatted&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc format;
value $mysex
'Male'=' Male'
'Female'='Female'
;
run;

proc ttest data=sashelp.heart alpha=0.05 order=Formatted;
class sex;
format sex $mysex.;
var weight;
run;&lt;/PRE&gt;
&lt;P&gt;A side effect of most of the ODS output is that the space in front of the M that makes " M" come before "F" alphabetically is that the space is justified out of appearance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since T-test class variables should only have two levels it usually isn't that hard to come up with a format quickly.&lt;/P&gt;
&lt;P&gt;It may be of interest that you can create the two groups for Ttest from a continuous or multivalued categorical variable by using a format.&lt;/P&gt;
&lt;PRE&gt;proc format;
value tage
low-14='14 and younger'
15-high= 'Over 14';
run;

proc ttest data=sashelp.class alpha=0.05 order=Formatted;
class age;
format age tage.;
var weight;
run;&lt;/PRE&gt;
&lt;P&gt;This can be very useful if you need a "this value" compared to "all the other values" of a category and pretty easy to code&lt;/P&gt;
&lt;PRE&gt;proc format;
value oage
14='14'
other= 'Not 14';
run;

proc ttest data=sashelp.class alpha=0.05 order=Formatted;
class age;
format age oage.;
var weight;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Apr 2023 17:25:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Software-for-Learning/How-to-swap-sex-type-in-proc-ttest-so-that-males-are-shown/m-p/868636#M1074</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-04-07T17:25:34Z</dc:date>
    </item>
  </channel>
</rss>

