Hi SAS users-
I originally had a numeric variable, SubjectID, that had a length of 6 but the value displayed was up to 11 digits. I accidentally thought this numeric variable was actually a character, so I converted it to numeric even though it was already numeric. (See SAS code below for my conversion step.)
This resulted in truncated values of the original variable, e.g. 20000000021 is now 20000000. Is there anyway to retrieve the original value of SubjectID? Or is it gone for good?
Thanks!
data convert;
set have (rename=(SubjectID=chrx_SubjectID));
length SubjectID 8.
SubjectID=input(chrx_SubjectID,8.);
run;
If you ran that code then your original value is in the variable CHRX_SUBJECTID.
What happens if you run this test:
data _null_;
set convert obs=4 ;
put SubjectID= chrx_SubjectID= ;
run;
You should be able to go back to your original data source and retrieve the 11 digit number.
By my original data source, are you referring to the "Have" dataset? If so, that dataset is no longer available. The only one I have access to is the 'convert' dataset.
If you ran that code then your original value is in the variable CHRX_SUBJECTID.
What happens if you run this test:
data _null_;
set convert obs=4 ;
put SubjectID= chrx_SubjectID= ;
run;
That sounds like a pretty dangerous combination:
Hopefully you can learn from this for next time.
Hi @sophia_SAS,
As to your initial surprise about the length of SubjectID: The length of a numeric variable does not specify the maximum number of digits, but the number of bytes used to store the numeric values internally.
The length limits the precision to which numbers can be stored. In particular, there are "largest integers that can be safely stored in a given length": see the table in "Numerical Accuracy in SAS Software."
As you see in the table, on Windows and Unix systems length 6 (bytes) is sufficient for integers with 11 digits (and even for a limited range of 12-digit integers), whereas 5 bytes or less would be insufficient. An insufficient length means that certain integers beyond the limit are rounded to multiples of 2, 4, 8, 16, ... (powers of 2) and the effects on non-integer values are even more difficult to deal with.
Your program (but only with a semicolon after the LENGTH statement, rather than a period) has created the "truncated" versions of the original values in the following way:
To resolve the issue (as Tom has already mentioned), it should be no problem to drop the newly created variable SubjectID and rename chrx_SubjectID back to SubjectID:
data want;
set convert;
drop SubjectID;
rename chrx_SubjectID=SubjectID;
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.