Hello, I came across the following problem in the example data:
Hello @PatrykSAS,
The VERIFY function would avoid potential length issues:
data have;
input id $;
cards;
003
0101
150
00070
;
data want;
set have;
id=substr(id,verify(id,'0'));
run;
I would start with something like:
data want; set have; id = put(input(id,best.),best. -L); run;
which may have some dependencies on length of values.
Next I would examine where the data came from, why it is in an undesired format, and read into SAS as needed.
BTW, if this is force values to match another NUMERIC value created with a different read/import then you have other issues because this is a Character value.
I suppose the ID is defined as char type variable.
then convert it to numeric by:
data want;
set have(rename=(ID=_ID);
id = input(_ID, best5.);
format ID 5.;
run;
Hello @PatrykSAS,
The VERIFY function would avoid potential length issues:
data have;
input id $;
cards;
003
0101
150
00070
;
data want;
set have;
id=substr(id,verify(id,'0'));
run;
The prxchange function is another possibility for character strings:
data want; set have; newid = prxchange('s/^(0*)(.*)/$2/', 1, id); run;
data have;
input id $;
cards;
003
0101
150
00070
;
data want;
set have;
new_id=prxchange('s/^0+//',1,id);
run;
Register today and join us virtually on June 16!
sasglobalforum.com | #SASGF
View now: on-demand content for SAS users
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.