Somewhere along the way, the decimal points got dropped from a portion of my dataset, and I am trying to put them back in. I know that they go after the first character.
The field is called Weight, and is numeric with nine decimal places. Here's an idea:
DATA LIST FREE / Weight (f11.9).
BEGIN DATA.
12736489222, 738572978222, 82928375623, 1.0293847562, 0.8273628367, 0.9283740189
END DATA.
This is the code I'm currently using:
string weightString3(a11).
COMPUTE weightString3 = string(Weight,f11.9).
EXECUTE.
NUMERIC weightFixed3(f11.9).
COMPUTE weightFixed3 = 0.
IF (Weight < 0.5) weightFixed3 = Weight.
IF (Weight > 0.5) weightFixed3 = NUMBER(CONCAT(char.substr(weightString3,1,1),".",char.substr(weightString3,2)), f11).
EXECUTE.
This is throwing an error, because NUMBER is adding a decimal point to the end of my strings - which already contain decimal points thanks to "." in CONCAT. So 738572978222 should be "7.385729782", but instead it becomes "7.385729782.", which isn't a valid number format so it gets set as SYSTEM MISSING.
I can't rstrip the final "." because it's a numeric variable, and if I convert it to string for rstrip and then back to numeric it'll just happen again. Specifying 'f11.0' for the number format didn't help either. Any ideas? Is there a smarter way to insert the "." I need than the CONCAT and SUBSTR functions?