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
| num | number |
| 2365 | 252365 |
| 8467 | 258467 |
| 253679 | 25253679 |
| 4533 | 254533 |
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;
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.
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;
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 ;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.