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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

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
  • 1 reply
  • 1306 views
  • 0 likes
  • 2 in conversation