DATA Step, Macro, Functions and more

How to delete values that have "_U" in the end

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

How to delete values that have "_U" in the end

I want to delete values/rows which are appended with "_U" in the end.


Accepted Solutions
Solution
‎01-17-2018 03:19 AM
PROC Star
Posts: 1,400

Re: How to delete values that have "_U" in the end

Posted in reply to Abhi301812
data have;
string="SomeString_U";output;
string="SomeString";output;
string="Some_UString";output;
run;

data want;
	set have;
	where substrn(string,max(1,length(string)-1),2) ne "_U";
run;

View solution in original post


All Replies
Solution
‎01-17-2018 03:19 AM
PROC Star
Posts: 1,400

Re: How to delete values that have "_U" in the end

Posted in reply to Abhi301812
data have;
string="SomeString_U";output;
string="SomeString";output;
string="Some_UString";output;
run;

data want;
	set have;
	where substrn(string,max(1,length(string)-1),2) ne "_U";
run;
New Contributor
Posts: 2

Re: How to delete values that have "_U" in the end

Thanks, this was helpful
PROC Star
Posts: 1,400

Re: How to delete values that have "_U" in the end

Posted in reply to Abhi301812

Anytime, glad to help Smiley Happy

Super User
Super User
Posts: 9,840

Re: How to delete values that have "_U" in the end

Or for succinctness:

data have;
string="SomeString_U";output;
string="SomeString";output;
string="Some_UString";output;
run;

data want;
  set have;
  where index(string,"_U");
run;

As a tip @draycut, could you use spaces rather than tabs to indent, as tabs get shown differently in different editors Smiley Happy

SAS Super FREQ
Posts: 830

Re: How to delete values that have "_U" in the end

Posted in reply to Abhi301812
Please provide some sample data in the form of a DATA Step

See this post on how to convert your SAS data set into a DATA Step program that creates this data
https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 117 views
  • 0 likes
  • 4 in conversation