I'm looking for a way to subset a dataset to only its categorical variables (or only continuous, doesn't matter) without knowing the names of the variables. So far haven't found anything that matches what I need. Thanks for any help.
Example:
data cars;
set sashelp.cars(keep=_character_);
run;
Example:
data cars;
set sashelp.cars(keep=_character_);
run;
If you use SAS Studio, check out the characterize data set task. It does this automatically by looking at the # of distinct values within variables. Anything less than a threshold will be classified as categorical IIRC.
@dbjosiah wrote:
Thanks Reeza. Once I have the real continuous ones out, I'm subsetting the long character ones by hand.
You could try NLEVELS output of PROC FREQ to quickly find the number of levels for each variable.
proc freq nlevels data=have;
tables _all_ / noprint;
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.