Hi All,
I think I have an easy one and multiple ways to go about it but I just can't get it to work as I'm used to character formats and I'm trying to do this with a numeric.
Datahave
123456789
Datawant
896712345
Last two become the first two, second to last 2 become the 2nd 2 and finally first 5 become last 5.
Use a character value as go-between:
charval = put(numval,z9.);
charval = substr(charval,8,2) !! substr(charval,6,2) !! substr(charval,1,5);
numval_new = input(charval,9.);
drop charval;
Another, pure numerical way would involve multiple use of divisions, INT and MOD functions.
Use a character value as go-between:
charval = put(numval,z9.);
charval = substr(charval,8,2) !! substr(charval,6,2) !! substr(charval,1,5);
numval_new = input(charval,9.);
drop charval;
Another, pure numerical way would involve multiple use of divisions, INT and MOD functions.
A purely numeric method would be:
data test;
array _i{9};
array _o{*} _i8 _i9 _i6 _i7 _i1 _i2 _i3 _i4 _i5;
numIn = 123456789;
_x = numIn;
do i = dim(_i) to 1 by -1;
_i{i} = mod(_x, 10);
_x = int(_x/10);
end;
_x = 0;
do i = 1 to dim(_o);
_x = _x*10 + _o{i};
end;
numOut = _x;
drop i _:;
run;
This kind of math occurs behind the scene whenever you convert between number and character.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Lock in the best rate now before the price increases on April 1.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.