BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
wajmsu
Obsidian | Level 7

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

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

View solution in original post

6 REPLIES 6
rayIII
SAS Employee

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

 

 

wajmsu
Obsidian | Level 7

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

PGStats
Opal | Level 21

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
Reeza
Super User

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;
wajmsu
Obsidian | Level 7

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

Reeza
Super User

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 2031 views
  • 4 likes
  • 4 in conversation