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.

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
  • 4 replies
  • 4401 views
  • 6 likes
  • 3 in conversation