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

Using SAS 9.4

 

I am having trouble converting numeric data into character data. I am using the following code:

data want;
set have;
med2_dose = input(med2_dose, 6.);
run;

 

The data are purely numbers (ie 1, 20, 25, 100, 250, etc.)

 

Whenever I run this code all of the numeric data is lost in the new variable but it is converted to character. Does anyone know how to correct this? Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Converting numeric to character uses the PUT function, not the INPUT function. You also have to name the resulting character variables something different than the original numeric variable.


Why on earth would you want dose to be character and not numeric?

--
Paige Miller

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

Converting numeric to character uses the PUT function, not the INPUT function. You also have to name the resulting character variables something different than the original numeric variable.


Why on earth would you want dose to be character and not numeric?

--
Paige Miller
GS2
Obsidian | Level 7 GS2
Obsidian | Level 7

I am combining 2 data sets and I need the variables to be the same (character or numeric) in order to stack the data sets together. However, in one of the data sets dose is a character because of the way the data was enter 10/325 for example. 

PaigeMiller
Diamond | Level 26

@GS2 wrote:

I am combining 2 data sets and I need the variables to be the same (character or numeric) in order to stack the data sets together. However, in one of the data sets dose is a character because of the way the data was enter 10/325 for example. 


Had I known that, I would have provided a different solution. Convert the character variable to be numeric. Then "combining" the two data sets will be possible, and dose will have the usefulness that you can analyze it as a number.

--
Paige Miller
novinosrin
Tourmaline | Level 20

Hi @GS2 

 

data want;
set have;
med2_dose_char = put(med2_dose, 6.);
run;

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!

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
  • 4 replies
  • 119866 views
  • 1 like
  • 3 in conversation