BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
ChuksManuel
Pyrite | Level 9

Hi programmers,

 

I am trying to test for association of 2 variables using the proc freq procedure for a predictor that has 4 levels against an outcome that has 5 categories.

 

I specifically want to select 2 levels of the predictor and not use all 4 in this test. I have tried the "where" statement but i haven't gotten any success.

 

I like to know where the issue could come from.

proc freq data = A;
tables group*birth
/chisq cmh;
where birth = ('Yes'  'No');
run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

@ChuksManuel wrote:
Hi I did that and it's telling me that there were zero observations read from the dataset.

In addition to what @Kurt_Bremser said, you need to look at the data set with your own eyes to see why "Yes" is not found in the data set, and why "No" is not found in the data set. It is possible that your variable BIRTH is formatted and so the actual values are 0 or 1 (or some other values).

 

You can look at the unformatted values by running PROC FREQ again without the WHERE statement and adding in

 

format birth;

which removes the formatting from the variable, or in whatever data set viewer you use you can also indicate that you want to remove the format from BIRTH.

 

But here we get into the problem that you are getting incorrect results, and you have not shown us the LOG, which would be extremely helpful, and should be something you show us every single time there are problems identified in the LOG. That's EVERY SINGLE TIME.

--
Paige Miller

View solution in original post

6 REPLIES 6
PaigeMiller
Diamond | Level 26
where birth in ("Yes" "No");
--
Paige Miller
ChuksManuel
Pyrite | Level 9
Hi I did that and it's telling me that there were zero observations read from the dataset.
Kurt_Bremser
Super User

Always beware of the "hidden blanks" used to patch up the unused space in character variables:

where strip(birth) in ("Yes","No");

And make sure you get your spelling absolutely right. "Yes" ^= "yes"!

PaigeMiller
Diamond | Level 26

@ChuksManuel wrote:
Hi I did that and it's telling me that there were zero observations read from the dataset.

In addition to what @Kurt_Bremser said, you need to look at the data set with your own eyes to see why "Yes" is not found in the data set, and why "No" is not found in the data set. It is possible that your variable BIRTH is formatted and so the actual values are 0 or 1 (or some other values).

 

You can look at the unformatted values by running PROC FREQ again without the WHERE statement and adding in

 

format birth;

which removes the formatting from the variable, or in whatever data set viewer you use you can also indicate that you want to remove the format from BIRTH.

 

But here we get into the problem that you are getting incorrect results, and you have not shown us the LOG, which would be extremely helpful, and should be something you show us every single time there are problems identified in the LOG. That's EVERY SINGLE TIME.

--
Paige Miller
ChuksManuel
Pyrite | Level 9
Yes. Formatting was the reason.
Tom
Super User Tom
Super User

You need IN operator not equality operator to select multiple values.

The values have be the actual values of the variable, not the formatted values.  

 

For character variables the value has to match exactly.  Case matters. Trailing spaces don't matter, but leading spaces do.

 

where lowcase(left(birth)) in ('yes'  'no');

 

If the variable is actually numeric with a format that displays two (or more) of the values as Yes and No then you need to use the actual numeric values in your list of values. 

 

where birth in (0 1);

 

Or perhaps use the format in the WHERE statement.

where put(birth,birthfmt.) in ('Yes' 'No');

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 788 views
  • 1 like
  • 4 in conversation