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

Hello everyone, I'm new SAS user and could you please help me to solve some problem? how can I add some number to the existing variable? e.g. in this table it is shown that I added '25' to all the number in variable 'num' and got a new variable 'number'. One more thing, how can I calculate how many elements does each data have? e.g. 2364 has 4, 8467 again 4, 253679 has 6 and so on . So I want to have another column that will reflect the length of each data. I used function length but it did not work. 

thank you in advance

numnumber
2365252365
8467258467
25367925253679
4533254533
1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

data have;
input num;*	number;
cards;
2365	252365
8467	258467
253679	25253679
4533	254533
;

data want;
 set have;
 new_num=input(cats('25',num),32.);
 length=lengthn(cats(num));
run;

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

Assuming the original variable is a character variable (is it?), this will prepend the characters '25' in front of it.

 

number=cats('25',num);

Actually, the above ought to work even if NUM is numeric and not character, but NUMBER will always be character.

 

As far as how many elements each string has, you can use the LENGTH() function.

--
Paige Miller
novinosrin
Tourmaline | Level 20

data have;
input num;*	number;
cards;
2365	252365
8467	258467
253679	25253679
4533	254533
;

data want;
 set have;
 new_num=input(cats('25',num),32.);
 length=lengthn(cats(num));
run;
Ksharp
Super User

Assuming it was always positive number.

data have;
input num;
new= 25*10**(int(log10(num))+1) + num;
cards;
2365	252365
8467	258467
253679	25253679
4533	254533
;

 

SAS Innovate 2025: Register Now

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 994 views
  • 5 likes
  • 4 in conversation