BookmarkSubscribeRSS Feed
sas_sad
Calcite | Level 5

Hello,

 

I am trying to convert a scale variable (0-5) that SAS read as character not sure why because in STATA, it was numeric and even in excel from where I read into SAS. The variable has decimals like 2.5,3.5. I tried converting it to numeric, but it is not working. That is my code blow and then I get following message in logs. Not sure what that means, please help me to convert this to numeric. Thanks!

NOTE: Numeric values have been converted to character values at the places given by:
(Line):(Column).
438:13

data mco;
set mco; overallrt = input(overallrt, best12.); run;

 

2 REPLIES 2
data_null__
Jade | Level 19

You need a new variable.

 

_overallrt = input(overallrt, best12.);
Tom
Super User Tom
Super User

You are converting the character string to a number and then assigning the number back into the same character variable.

 

You need to create a new numeric variable to hold the numeric value.

 

It is better not to overwrite you original dataset, you might need to recreate MCO from whatever source you used to create it originally. Also depending on how you created it you might be able to fix the issue there.

 

Also BEST is a FORMAT, not an INFORMAT.  Using it as an INFORMAT will just cause SAS to use the normal numeric informat. (Note if the strings have thousands separators then use the COMMA informat instead, in may ways that is the "best" informat.).  The INPUT function does not care if the width you use on the informat is longer than the length of the character string. The maximum width the normal numeric informat can use is 32.

 

data fixed_mco;
  set mco;
  overallrt_num = input(overallrt, 32.);
run;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 615 views
  • 0 likes
  • 3 in conversation