- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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 -
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.);
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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 -
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
my apologies, but i have just realized that my observations are actually Character format, sorry.
i cant get your suggestions to work and i think this is why. Could you rethink please?
thanks again.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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 ) ;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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 -
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;