DATA Step, Macro, Functions and more

Where condition

Accepted Solution Solved
Reply
Contributor
Posts: 31
Accepted Solution

Where condition

Given the SAS data set EMPLOYEES:
EMPLOYEES
NAME SALARY
-------- ------------
Innis60000
Jolli50000
Ellis55000
Liu45000
The following SAS program is submitted:
proc print data = employees; where name like ‘_i%’;
run;
What is contained in the output?
A. Liu only
B. Innis and Ellis only
C. Innis, Ellis, and Liu only
D. Innis, Jolli, Ellis, and Liu

 

Why is the answer "A"??

I do not actually understand the condition name like '_i%'. Thanks!


Accepted Solutions
Solution
‎09-27-2017 05:46 AM
Super User
Posts: 7,846

Re: Where condition

There is a reason why Maxim #1 (Read the documentation) is number one.

From http://documentation.sas.com/?docsetId=lrcon&docsetTarget=p0eaz2e63dlj17n1i5z17z3h84vp.htm&docsetVer..., section LIKE Operator:

 

underscore (_)
matches just one character in the value for each underscore character.

 

so there must be exactly one character before the "i", and only Liu satisfies this.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Solution
‎09-27-2017 05:46 AM
Super User
Posts: 7,846

Re: Where condition

There is a reason why Maxim #1 (Read the documentation) is number one.

From http://documentation.sas.com/?docsetId=lrcon&docsetTarget=p0eaz2e63dlj17n1i5z17z3h84vp.htm&docsetVer..., section LIKE Operator:

 

underscore (_)
matches just one character in the value for each underscore character.

 

so there must be exactly one character before the "i", and only Liu satisfies this.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
☑ This topic is solved.

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

Discussion stats
  • 1 reply
  • 107 views
  • 1 like
  • 2 in conversation