Hi guys,
I'm trying to convert a character variable to numeric.
The variable represents IDs (i.e., anonymized patients) I received from an hospital.
While converting to numeric, the last value is trimmed. For example: 800501185 becomes 80050118. Is there a way to prevent the trimming?
Here the code I'm using:
data myDATA;
set myDATA;
numeric_var = input(Patients, 8.);
put numeric_var=;
run;
Original variable "Patients": Char $11.
Thank you in advance
data myDATA;
Patients='800501185';
numeric_var = input(Patients, best32.);
put numeric_var=;
run;
data myDATA;
Patients='800501185';
numeric_var = input(Patients, best32.);
put numeric_var=;
run;
DON'T.
Patient ID's are codes, not numbers, and should always be stored as character. You will never do calculations with them, but numeric might lead to imprecisions or loss of information (like leading zeroes).
Technically, your program instructs SAS to read 8 characters:
numeric_var = input(Patients, 8.);
That's what "8." means: read 8 characters. If you want SAS to read a different number of characters, that's the statement to change, perhaps to one of.
numeric_var = input(Patients, 9.);
numeric_var = input(Patients, 11.);
The solution from @yabwon will work. But technically, "best32." is a format, not an informat. So SAS just changes "best32." automatically to be "32." and gets the proper result.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.