2

Can anyone please tell me how to select only numeric or character variables?

flag

2 Answers

5

If you are trying to create a dataset selecting only the variables that are character (or numeric) you can use the keep statement with char or numeric respectively. Here's an example with the SAS class dataset:

data work.numeric_only;
set sashelp.class(keep=_numeric_);
run;

data work.char_only;
set sashelp.class(keep=_char_);
run;
link|flag
3

If you want to know whether the variable itself is a numeric or character type you can use the VARTYPE(data-set-id,var-num) function. The var-num is the number of the variable as shown in the PROC CONTENTS for that dataset.

c.f. http://support.sas.com/documentation/cdl/en/lrdict/62618/HTML/default/a000148439.htm ; it has a fuller explanation and some code examples.

If you are trying do determine whether the content of the variable for a particular observation is numeric or character you can use the VTYPE(var) function. I can't give the reference link because I am a new user to runsumbit.

Run;

link|flag

Your Answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.