How to classify repeat data entry?

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 82
Accepted Solution

How to classify repeat data entry?

Dear All,

I have a data set below. I am trying to use proc ttest to compare T of left side and right side ( if name ='lm' 'ls' then leftside=1; if name='rm'  'rs' then leftside=0). The error showed ' all observations are missing a class value'.

s name T

1 lm      8

1 rm     9

2 lm      7

2 rm      8

3 ls       9

3 rs       7

4 ls      10

4 rs       9 

is there a way to solve this problem?

Thanks so much


Accepted Solutions
Solution
‎07-20-2015 05:44 PM
Super User
Posts: 17,829

Re: How to classify repeat data entry?

You don't need t-test, you need a more complicated analysis - most likely proc mixed or GLM which deal with repeated measures.

However you shouldn't get that error from T-Test, as it means you're doing something incorrect.

data have;

input s name $ T ;

cards;

1 lm  8

1 rm  9

2 lm  7

2 rm  8

3 ls  9

3 rs  7

4 ls  10

4 rs  9

;

run;

proc print data=have;run;

data want;

set have;

if name in ('lm', 'ls') then leftside=1; /*left side*/

else if name in ('rm', 'rs') then leftside=0; /*rightside*/

else leftside=-1; /*catch mistakes*/

run;

proc ttest data=want;

class leftside;

var t;

run;

View solution in original post


All Replies
Super User
Posts: 10,500

Re: How to classify repeat data entry?

Did you actually add the variable before running the t-test, as in verify that you had values?

You should have gotten errors if you used

if name ='lm' 'ls' then leftside=1; if name='rm'  'rs' then leftside=0

in a data step.

The code for that assignment would be better as:

if name in ('lm' 'ls') then leftside=1; else if name in ('rm'  'rs') then leftside=0;

Or if  the only values for Name are 'lm' 'ls' 'rm' 'rs' and is never missing you could use:

Leftside = (name in ('lm' 'ls'));

Frequent Contributor
Posts: 82

Re: How to classify repeat data entry?

I tried your way to code leftside in data step, and get the same result.

My code for t test:

proc ttest data=want;

class leftside;

var T;

run;

Just like Reeza said, the problem is related to more than one measurement for each category such as 2 lm and 2 ls etc.

should I combine each category first? and how to combine it?

Thanks

Super User
Posts: 10,500

Re: How to classify repeat data entry?

I tried your way to code leftside in data step, and get the same result.

Please show your original code.

Also is the case of the name variable always the same and as shown in your example? Are there leading spaces?

You might need if upcase(strip(name)) in ('LM', 'LS') then leftside=1;

If the 1 2 and such shown are part of the name then you need to remove those before the comparison.

Large economy sized hint: Before running any test or modeling procedures ensure that the data fed to the procedure is as needed.

Frequent Contributor
Posts: 82

Re: How to classify repeat data entry?

Hi Ballardw,

Thanks for your help. There are 3 variables: s, name and T. the data set actually is in excel file, s and name are separate variables. S means slice number of MRI. name represent of part of human body, and T means tissue transit time.  I want to compare the difference between left and right side. the problem is some part of body have more than one slide of scanning.

When I do:

proc means data=want;

class leftside;

var T;

run;

the log window showed :

WARNING: A class or frequency variable is missing on every observation.

Do I need to get mean of lm or ls first, then let lm or ls has only one value?

Thanks,

Solution
‎07-20-2015 05:44 PM
Super User
Posts: 17,829

Re: How to classify repeat data entry?

You don't need t-test, you need a more complicated analysis - most likely proc mixed or GLM which deal with repeated measures.

However you shouldn't get that error from T-Test, as it means you're doing something incorrect.

data have;

input s name $ T ;

cards;

1 lm  8

1 rm  9

2 lm  7

2 rm  8

3 ls  9

3 rs  7

4 ls  10

4 rs  9

;

run;

proc print data=have;run;

data want;

set have;

if name in ('lm', 'ls') then leftside=1; /*left side*/

else if name in ('rm', 'rs') then leftside=0; /*rightside*/

else leftside=-1; /*catch mistakes*/

run;

proc ttest data=want;

class leftside;

var t;

run;

Frequent Contributor
Posts: 82

Re: How to classify repeat data entry?

Hi Reeza,
Thanks so much for your help. It works well when I copied your code to SAS.

when I used same code with excel file for proc ttest, then showed:

ERROR: The CLASS variable does not have two levels.

I have tried many times, I have no idea when it won't work for excel file.

Thanks,

Super User
Posts: 17,829

Re: How to classify repeat data entry?

As BallardW has mentioned above, you need to verify your source data. Without seeing your previous steps we can only go on what you've told us. 

Make sure you're importing your Excel file properly and the fields are being read appropriately. Run a proc print on your input data and check for errors.

Run a proc freq on the NAME variable to make sure you're seeing the same observations, and note that string comparisons and recoding is case sensitive, ie data points LM and lm are different. 

Frequent Contributor
Posts: 82

Re: How to classify repeat data entry?


Hi Reeza,

I figured out the problem with source data. I really appreciate you, and others' help.

Super User
Posts: 17,829

Re: How to classify repeat data entry?

What is your proc ttest code? I don't think you should need to recode right/left side as the CLASS variable can be numeric or character.

Oops - missed the fact that you have two measurements for each side.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 9 replies
  • 422 views
  • 0 likes
  • 3 in conversation