Deleting Certain Categories within a Variable

Reply
New Contributor MN
New Contributor
Posts: 3

Deleting Certain Categories within a Variable

Hello,

I have a categorical variable, labelled 0-9. I need to delete certain values so I can run a CHISQ.

This is what I'm trying, but with no luck:

DATA mn.lahrt; *my dataset*

  SET IHD_DX; *the variable name*

  IF IHD_DX = 0 THEN delete;

  IF IHD_DX = 8 and 9 Then delete;

RUN;


I need to keep categories 1-7 only (which are further split in only two categories).


Any suggestions?

Super Contributor
Posts: 349

Re: Deleting Certain Categories within a Variable

Hi ,

Try this..Hope it helps

DATA mn.lahrt;

  SET mn.lahrt;

  IF IHD_DX  in ('0','8','9') THEN delete;

RUN;

Thanks,

Shiva

New Contributor MN
New Contributor
Posts: 3

Re: Deleting Certain Categories within a Variable

Thank You for your help. Though that didn't really work for my data-set, so I just exported it to excel and made the needed changes.

Super User
Super User
Posts: 7,039

Re: Deleting Certain Categories within a Variable

Your language is very confused.  Sounds to me like you have a variable named IHD_DX in a dataset named MN.LAHRT.

You would not normally want to overwrite your input dataset as in your example code.  In fact to limit data you can just use a WHERE statement in your procedure calls.

proc freq data=mn.lahrt ;

where 1<= idh_dx <= 7 ;

tables idh_dx / chisq ;

run;

I am not sure what you mean by "labeled" values. Is it possible that the actual values in IDH_DX variable are something other than the values 0,1,....9 ?  Do you have a format attached?

You can also use formats to temporarily regroup you data for a PROC FREQ call.  For example if you want to regroup your values into two groups you might use something like:

proc format ;

value group 1-7 = 'VALID' other='INVALID';

run;

proc freq data=mn.lahrt;

  format idh_dx group.;

  tables idh_dx;

run;

New Contributor MN
New Contributor
Posts: 3

Re: Deleting Certain Categories within a Variable

Thank You for your help. Though that didn't really work for my data-set, so I just exported it to excel and made the needed changes.

Ask a Question
Discussion stats
  • 4 replies
  • 1068 views
  • 6 likes
  • 3 in conversation