BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
nmlynar13
Calcite | Level 5

I am trying to merge a few datasets I have. I get the following error:

 

ERROR: Variable year1 has been defined as both character and numeric.

 

I understand what it means and how it works, however, I am wondering if there is a simple line to convert all observations in the data to numeric (or character for that matter) at once.

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

No there isn't. You use the INPUT function to convert from character to numeric or the PUT function for numeric to character. You can use arrays to convert a lot of variables at a time but that still requires a minimum of four statements - an ARRAY, a DO, an INPUT function with an assignment, and an END. 

View solution in original post

3 REPLIES 3
SASKiwi
PROC Star

No there isn't. You use the INPUT function to convert from character to numeric or the PUT function for numeric to character. You can use arrays to convert a lot of variables at a time but that still requires a minimum of four statements - an ARRAY, a DO, an INPUT function with an assignment, and an END. 

nmlynar13
Calcite | Level 5
Thank you for the help, I'll try that out!
Amir
PROC Star

Hi @nmlynar13,

 

In addition to what has already been said, note that the variable itself has a type (character or numeric), the type of the variable cannot be changed, a new variable of the desired type will have to be created to hold the converted value, as in the example below. If desired, drop and rename data set options or statements can be used to have the same variable name on the output data set.

 

data have;
   set sashelp.class;

   /* create a character variable age2 to hold the value of numeric variable age */ 
   age2 = put(age,8.);
run;

 

 

Kind regards,

Amir.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 3 replies
  • 617 views
  • 0 likes
  • 3 in conversation