Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Home
- /
- Programming
- /
- SAS Procedures
- /
- Proc ttest: class continuous variable

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 08-22-2016 03:48 PM
(1321 views)

Hi all,

I have a simple mission yet with a complication I have not found a way to solve. I want to do a two-sample t-test by a continuous variable.

Say I have variables con1 and con2, both are continuous. I want to see if in group 1 (con1>=median of con1 across whole sample) vs. in group 2 (con1<median of con1 across whole sample), values of con2 are different. Below is what I have right now:

proc univariate data=have; var con1; run; /* manually get con1 median, say the median is 1.523*/

data a1; set have;

if con1>= 1.523 then dummy=1; if con1< 1.523 then dummy=0; if con1=. then dummy=.;

run;

proc ttest data=a1; class dummy; var con2; run;

Essentially I manually get the median of con1, and make a categorical variable based on the median ("dummy" in the above example) . The problem with this is: due to rounding, though the median really is 1.522823104, SAS output would show median of 1.523. And this makes the sample sizes of group1 and group2 vastly different. I want to make sure that group1 and group2 have the same size (or different by 1 if whole sample size is an odd number). Is there an easy way of doing this?

I appreciate any help!

JOL

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

You can have Univariate output percentiles using the OUTPUT statment. The values will have more precision than the output really designed for people to look at which will likely be rounded as you say.

But to create groups Proc Rank may be much easier

```
proc rank data=have groups=2;
var con1;
ranks dummy;
run;
```

The dummy will have 0 for the values below the median and 1 for above. Note no need for univariate. You can use Proc rank to generate different numbers of groups: 4 would be quartiles, 10 deciles, 100 percentiles.

2 REPLIES 2

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

You can have Univariate output percentiles using the OUTPUT statment. The values will have more precision than the output really designed for people to look at which will likely be rounded as you say.

But to create groups Proc Rank may be much easier

```
proc rank data=have groups=2;
var con1;
ranks dummy;
run;
```

The dummy will have 0 for the values below the median and 1 for above. Note no need for univariate. You can use Proc rank to generate different numbers of groups: 4 would be quartiles, 10 deciles, 100 percentiles.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Hi ballardw,

Thanks for the response! I did what you suggested, and it worked much better (though still not what I had hoped for, but I suppose I can settle with the much smaller sample size difference).

For future reference, below is what I had in the end:

```
proc rank data=have groups=2 out=want;
var con1;
ranks dummy;
run;
```

Thanks for the help!

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

**If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. **

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.