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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.