How did you make the string to begin with? Why not just fix that step instead?
You can use the FINDC() command to find the last character before the trailing commas and periods start.
data test;
infile cards dsd truncover;
input @1 have $100. @1 (id1-id20) (:$30.);
want=catx(',', of id1-id20);
loc=findc(have,' ,.',-1000,'k');
want2=substrn(have,1,loc);
put (_all_) (=/);
cards;
18430109646000104331929350001,064380958490001,974317618110001,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.
;
have=18430109646000104331929350001,064380958490001,974317618110001,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.
id1=18430109646000104331929350001
id2=064380958490001
id3=974317618110001
id4=
id5=
id6=
id7=
id8=
id9=
id10=
id11=
id12=
id13=
id14=
id15=
id16=
id17=
id18=
id19=
id20=
want=18430109646000104331929350001,064380958490001,974317618110001
loc=61
want2=18430109646000104331929350001,064380958490001,974317618110001