BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Guru_MG
Fluorite | Level 6

Hi There,

 

what is the syntax to print only categorical variables in a dataset? 

 

For eg: Syntax to print only numeric variables in a dataset is 

proc print data=sashelp.cars;
var _numeric_;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
4 REPLIES 4
PaigeMiller
Diamond | Level 26

Use

 

var _character_;
--
Paige Miller
Guru_MG
Fluorite | Level 6

Thank you very much Pagiemiller 🙂

Tom
Super User Tom
Super User

SAS has two variable types. Floating point numbers and fixed length character strings. Whether a variable is categorical or not is something that SAS does not know.  You would have to tell it.

 

The _NUMERIC_ variable list includes all of the numeric variables (whether they are "categorical" or not).  The _CHARACTER_ variable list includes all of the character variables (whether they have defined categories or are free text).

ballardw
Super User

Since SAS doesn't know which variables are 'categorical' you might look into the Proc freq NLEVELS option

 

ods select nlevels;
proc freq data=sashelp.class nlevels;
run;

As an example. The ODS SELECT option will have Proc Freq only display the NLEVELS table and not every single value of every single variable in the data set.

This shows the number of different values a variable has. In this case AGE, which is numeric, shows 6 values and might be considered "categorical". Name, which has 19 values in 19 records seems like less a "category" than "free text". Sex, character with 2 levels, likely would be a category.

 

The common meanings of the variable name in the SASHELP.CLASS data set may be sufficient but this technique may be helpful exploring a new data set.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 1166 views
  • 5 likes
  • 4 in conversation