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;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: