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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.