BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
pandhandj
Obsidian | Level 7

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

1 ACCEPTED SOLUTION

Accepted Solutions
Oligolas
Barite | Level 11
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 -

View solution in original post

7 REPLIES 7
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.);

Oligolas
Barite | Level 11

 

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 -

pandhandj
Obsidian | Level 7
Guys, thanks for the responses.

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.
Peter_C
Rhodochrosite | Level 12

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 ) ;

 

 

Oligolas
Barite | Level 11
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 -

pandhandj
Obsidian | Level 7
thanks to all...I'm cooking with gas now 🙂
Ksharp
Super User
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;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 13250 views
  • 2 likes
  • 5 in conversation