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;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.