I am sure this is very simple guys, but i am struggling.
i have a data set with 1 variable (numeric), its 10 digits long.
I need to at the same prefix to all observations (around 130,000 in total)
the prefix is numeric and is 4 digits long.
so,
have: 1234567890
want: 22221234567890
apologies if i am missing something obvious, but it has been an awfully long week so far...
thanks,
paul
data have;
length var $10;
var='1234567890';
run;
data want(rename=(var2=var));
length var2 $14;
set have;
var2=cats('2222',var);
drop var;
run;
- Cheers -
Well, if they are all 10 and you want the 2222, then you can just do:
value=value + 22220000000000;
I think I got the right number of zeroes there - adjust as per your testing 🐵
Alternatively if they are not all 10, then its probably simpler to convert to text, append then convert back to number:
value=put(cats("2222",input(value,best.),best.);
Hi,
if you always have 10 digits, you could simply add 22220000000000 to your value.
if not, you can convert it to char, add the prefix and reconvert to numeric, like this:
data have;
var=1234567890;
run;
data want;
length want1 want2 8;
set have;
want1=var+22220000000000;
want2=input('2222'||strip(put(var,best31.)),best31.);
format want1 want2 16.;
run;
Cheers
- Cheers -
that is called concatention
Have a look at the CATx functions (where x could be X S T or not present)
As stated you might want
new_string = cats( '222', old_string ) ;
data have;
length var $10;
var='1234567890';
run;
data want(rename=(var2=var));
length var2 $14;
set have;
var2=cats('2222',var);
drop var;
run;
- Cheers -
If you want numeric variable be that, try PICTURE: proc format; picture fmt low-high='00000000000000' (prefix='2222'); run; data have; have=1234567890; format have fmt.; run;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.