data l;
input userno $1-100;
cards;
00789
00000000000000000000000004567
000000000000000000000000000000000000000000000000000000000000004567
000000000000000000000000000000004567
4567
00000000056
00lo
000ui
run;
I am having a character varibale i want to supress if the variable is having leading
zero as i cant conver it to numeric as it hassome character data .
I cant to by substr as there are hudred length i cant write substr
or if condition
i wnat the out put like this
output
789
4567
4567
4567
4567
56
lo
ui
Hi,
Check this link https://communities.sas.com/thread/35500?start=0&tstart=0
Try this..but if you have any zeros in between or after then compress will not work....
data l;
input userno $ 1-67;
xx=compress(userno,0);
cards;
00789
00000000000000000000000004567
000000000000000000000000000000000000000000000000000000000000004567
000000000000000000000000000000004567
4567
00000000056
00lo
000ui
run;
Thanks,
Shiva
Message was edited by: shiva saidala
VERIFY and SUBSTRN
6178 data l;
6179 infile cards truncover;
6180 input userno $1-100;
6181 put 'NOTE: before: ' userno=;
6182 userno = substrn(userno,verify(userno,'0'));
6183 put 'NOTE- after : ' userno=;
6184 cards;
NOTE: before: userno=00789
after : userno=789
NOTE: before: userno=00000000000000000000000004567
after : userno=4567
NOTE: before: userno=000000000000000000000000000000000000000000000000000000000000004567
after : userno=4567
NOTE: before: userno=000000000000000000000000000000004567
after : userno=4567
NOTE: before: userno=4567
after : userno=4567
NOTE: before: userno=00000000056
after : userno=56
NOTE: before: userno=00lo
after : userno=lo
NOTE: before: userno=000ui
after : userno=ui
Hi ... just curious, why SUBSTRN versus SUBSTR as used by Ksharp? In this posting (leading zeroes), is there any instance where SUBSTRN will do anything that SUBSTR won't do? Thanks.
Yes you are correct I was thinking it needed SUBSTRN but it does not.
Mike,
There is no need to use substrn(), since VERIFY() would take care of it very well.
Ksharp
Here are two approach. First is using verify, Second is using PRX. I prefer to PRX.
data l; input userno : $100.; cards; 00789 00000000000000000000000004567 000000000000000000000000000000000000000000000000000000000000004567 000000000000000000000000000000004567 4567 00000000056 00lo 000ui ; run; data want; set l; new=substr(userno,verify(userno,'0')); run; new=prxchange('s/^0+//o',1,subjid);
Ksharp
data x;
set l;
z=compress(userno,'1234567890') ;
n=1*userno;
use=catx("",z,n);
use1=compress(use,".");
drop z n use;
run;
As a new bie I will be doing in this way ...please let me know any efficient ideas .
Giridhar.
This post is 3 years. Start a new question if needed, with test data and required output. If the initial post is to go by then:
new_var=strip(tranwrd(old_var,"0",""));
Should work.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.