BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
KC_16
Fluorite | Level 6

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

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20
data have;
Order_Number='12345678912,';
run;

proc sql;
    create table want as
    select Order_Number length=11
    from have;
quit;

View solution in original post

4 REPLIES 4
ballardw
Super User

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.

PeterClemmensen
Tourmaline | Level 20

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
KC_16
Fluorite | Level 6

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?

PeterClemmensen
Tourmaline | Level 20
data have;
Order_Number='12345678912,';
run;

proc sql;
    create table want as
    select Order_Number length=11
    from have;
quit;

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 498 views
  • 0 likes
  • 3 in conversation