Hi,
I have a variable (Order_Number) which typically has 11 numbers, in some instances, it has a ',' or a text after. Is there anyway to remove anything after the 11th Number please?
Thanks
data have;
Order_Number='12345678912,';
run;
proc sql;
create table want as
select Order_Number length=11
from have;
quit;
You say "typically", are the values you want ever shorter than 11?
in a data step:
string = substr(string,1,11);
will remove anything passed the 11th character.
I would simply set an appropriate length like this
data _null_;
length Order_Number $11;
Order_Number='12345678912,';
put Order_Number=;
run;
Result:
Order_Number=12345678912
Thanks for this, how would I do this using PROC SQL? I have 2 parts of inherited code so I need the logic in a Data step (thank you) and the same logic in a PROC SQL if possible please?
data have;
Order_Number='12345678912,';
run;
proc sql;
create table want as
select Order_Number length=11
from have;
quit;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.