07-10-2017 05:14 AM
Dear SAS users,
I have encountered problems in changing variable type from character to numeric.
Specifically, from my PROC CONTENTS results, a few variables have been labelled as categorical when they are numeric in nature, prohibiting the PROC UNIVARIATE to be executed successfully.
For example, the variable Number_of_pregnancies should be numeric, but it has been considered as categorical/character by SAS studio.So, PROC UNIVARIATE cannot proceed with it by showing error in the log file.
The error I have obtained has been illustrated in the attachment along this message, so please have a look at the image attached.
Could anyone kindly provide some hints on how to solve this issue?
07-10-2017 05:22 AM
First of all, I would get rid of all those idiotic 'some_hard_to_read_text'n names and use standard SAS-compatible names. 'XXXXXXXXX'n names only cause confusion and unnecessary work during typing.
'Smokes_(years)'n can easily be replaced by smokes_years without any loss of meaning.
If a variable that should be numeric is imported as character, you have to look at the data in the external file and correct the import process.
If a variable can't be corrected there, you have to replace it with a step like this:
%let varname=place_your_varname_here; data want; set have (rename=(&varname=__&varname)); &varname = input(__&varname,best.); /* use a proper informat here */ drop __&varname; run;