DATA Step, Macro, Functions and more

Class statement

Accepted Solution Solved
Reply
Contributor
Posts: 61
Accepted Solution

Class statement

Hi,

When can we use class statement? If I have a binary variable and using Proc Logistic, should I use class statement for that variable?

Thanks


Accepted Solutions
Solution
‎07-07-2016 05:06 PM
Super User
Posts: 19,772

Re: Class statement

It's true that you can and should use Class statement for binary variables, but its not a requirement.

View solution in original post


All Replies
SAS Employee
Posts: 106

Re: Class statement

The CLASS statement is used to declare categorical (as opposed to interval/continuous) predictor variables. Generally nominal variables (males/female, yes/no, event/nonevent) are treated as categorical. 

 

https://support.sas.com/documentation/cdl/en/statug/63347/HTML/default/viewer.htm#statug_logistic_se...

 

Any predictor variables that have type=character must be declared as class variables or you will get an error. 

 

Hope this helps.

 

Ray

 

 

Contributor
Posts: 61

Re: Class statement

Hi Ray,

Thanks for the response. Below are three different codes and I need guidance:

  • Which code is correct to use, as the third one does not have class statement in it?
  • according to my understanding, the third code should use last categoryof CMV_ca_2_1 (category 2) as reference; but the output of this code is the same as that of the output no.2 where I defined reference as 1 (which is not last category).

 

proc logistic data=pe.matchedata_21;
strata group;
class CMV_ca_2_1 (ref='2');
model PEstatus (event='1')= CMV_ca_2_1;
run;


proc logistic data=pe.matchedata_21;
strata group;
class CMV_ca_2_1 (ref='1');
model PEstatus (event='1')= CMV_ca_2_1;
run;

proc logistic data=pe.matchedata_21;
strata group;
model PEstatus (event='1')= CMV_ca_2_1;
run;

 

Thanks

Respected Advisor
Posts: 4,920

Re: Class statement

Use code #2 where you get what you want without having to rely on obscure default rules. That explicit coding will also be much easier to interpret 6 months from now.

PG
Super User
Posts: 19,772

Re: Class statement

In general you'll also want to specify your parameterization method. I don't know if it matters for 0/1 coding, but as suggested before, being explicit doesn't hurt. And defaults can change between versions of SAS so it's good to be explicit.

 

proc logistic data=pe.matchedata_21;
strata group;
class CMV_ca_2_1 (ref='1') / param=ref;
model PEstatus (event='1') = CMV_ca_2_1;
run;
Contributor
Posts: 61

Re: Class statement

Thanks PGStats and Reeza!

I wanted an expert endorsement to my understanding which I got. Just to reconfirm, this is true even for a binary variable to use the class statement with explicit reference indication.

Regards

Solution
‎07-07-2016 05:06 PM
Super User
Posts: 19,772

Re: Class statement

It's true that you can and should use Class statement for binary variables, but its not a requirement.

☑ This topic is solved.

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

Discussion stats
  • 6 replies
  • 399 views
  • 4 likes
  • 4 in conversation