BookmarkSubscribeRSS Feed
MN
Calcite | Level 5 MN
Calcite | Level 5

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?

4 REPLIES 4
shivas
Pyrite | Level 9

Hi ,

Try this..Hope it helps

DATA mn.lahrt;

  SET mn.lahrt;

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

RUN;

Thanks,

Shiva

MN
Calcite | Level 5 MN
Calcite | Level 5

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.

Tom
Super User Tom
Super User

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;

MN
Calcite | Level 5 MN
Calcite | Level 5

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.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 5458 views
  • 6 likes
  • 3 in conversation