BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
sasphd
Lapis Lazuli | Level 10

Hello I want to convert $50. to numeric. this is the dataset. when I run proc corr I have a error in the log "in list does not match type prescribed for this list" 

sasphd_0-1671383569943.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

The INPUT function is the preferred method, but here are a few more considerations.

 

First, you will need new variable names.  Existing character variables cannot be turned into numeric variables.  You could conceivably jump through some hoops to re-use the old names, which could look like this:

data want;
   set have;
   numvar = input(charvar, 20.);
   drop charvar;
   rename numvar = charvar;
run;

That would give you the original variable name as a numeric variable, but it's a tedious process to go through if you have many variables.

 

Second, you can trade off complexities of the programming if you are willing to tolerate notes in the log:

data want;
   set have;  
   length numvar 8;
   numvar = charvar;
run;

That gives you NUMVAR as the numeric version of CHARVAR, but adds a note to the log about character to numeric conversion.  

 

Finally, if you use the INPUT function, do not add number of decimal places:

data want;
   set have;
   numvar = input(charvar, 6.4);     /* gives the wrong result */
run;

Just supply the width to the INPUT function, not the number of positions after the decimal point.

View solution in original post

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

Use the Input Function with an appropriate informat.

Astounding
PROC Star

The INPUT function is the preferred method, but here are a few more considerations.

 

First, you will need new variable names.  Existing character variables cannot be turned into numeric variables.  You could conceivably jump through some hoops to re-use the old names, which could look like this:

data want;
   set have;
   numvar = input(charvar, 20.);
   drop charvar;
   rename numvar = charvar;
run;

That would give you the original variable name as a numeric variable, but it's a tedious process to go through if you have many variables.

 

Second, you can trade off complexities of the programming if you are willing to tolerate notes in the log:

data want;
   set have;  
   length numvar 8;
   numvar = charvar;
run;

That gives you NUMVAR as the numeric version of CHARVAR, but adds a note to the log about character to numeric conversion.  

 

Finally, if you use the INPUT function, do not add number of decimal places:

data want;
   set have;
   numvar = input(charvar, 6.4);     /* gives the wrong result */
run;

Just supply the width to the INPUT function, not the number of positions after the decimal point.

andreas_lds
Jade | Level 19

If the number has 50 digits, converting it to numeric will cause loss of precision.

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 1071 views
  • 2 likes
  • 4 in conversation