BookmarkSubscribeRSS Feed
kjyon2
Calcite | Level 5

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


error_variable_type_prescribed_list.PNG
1 REPLY 1
Kurt_Bremser
Super User

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;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1596 views
  • 0 likes
  • 2 in conversation