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

Hello friends,

 

I am trying to drop observations ending in "_A" of the variable, "category". I used the following code and didn't work. Could you please help?

 

If substr(category, - 1, 2)="_0" then delete;

 

Thank you and all have a wonderful weekend!

Rube

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

You cannot use negative numbers with SUBSTR().

if substrn(category,length(category)-1) = '_A' then delete;

You can use negative numbers with SCAN().

if scan(category,-1,'_') = 'A' then delete;

Do you ever have values that are just 'A' without any underscore?

Do you ever have values with lowercase a as the suffix?

if index(category,'_') and upcase(scan(category,-1,'_')) = 'A' then delete;

 

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

You cannot use negative numbers with SUBSTR().

if substrn(category,length(category)-1) = '_A' then delete;

You can use negative numbers with SCAN().

if scan(category,-1,'_') = 'A' then delete;

Do you ever have values that are just 'A' without any underscore?

Do you ever have values with lowercase a as the suffix?

if index(category,'_') and upcase(scan(category,-1,'_')) = 'A' then delete;

 

sandrube
Fluorite | Level 6
Thank you very much and have a great weekend!

Rube

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
  • 2 replies
  • 365 views
  • 1 like
  • 2 in conversation