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
Opal | Level 21

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
Astounding
Opal | Level 21

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
PROC Star

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

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 445 views
  • 2 likes
  • 4 in conversation