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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

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