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?
Regards,
Kevin
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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Get started using SAS Studio to write, run and debug your SAS programs.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.