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?
Hi ,
Try this..Hope it helps
DATA mn.lahrt;
SET mn.lahrt;
IF IHD_DX in ('0','8','9') THEN delete;
RUN;
Thanks,
Shiva
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.
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;
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.
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.
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.