BookmarkSubscribeRSS Feed
BrahmanandaRao
Lapis Lazuli | Level 10

Hi Guys,

suppose i have employees table in the table which names starts with 'K' and middle letter with 'L' and end with 'K' in employees name column

13 REPLIES 13
PaigeMiller
Diamond | Level 26

@BrahmanandaRao wrote:

 

suppose i have employees table in the table which names starts with 'K' and middle letter with 'L' and end with 'K' in employees name column


Okay, I am now in my mind supposing that you have this table. What would you like me to do next? Do you have an actual question?

--
Paige Miller
BrahmanandaRao
Lapis Lazuli | Level 10

Those names starts with k and middle letter L and end with k  whose names retrive

Kurt_Bremser
Super User

@BrahmanandaRao wrote:

Those names starts with k and middle letter L and end with k  whose names retrive


Yes. And?

 

Please turn on that thing between your ears and post a question.

 

PaigeMiller
Diamond | Level 26

@BrahmanandaRao wrote:

Those names starts with k and middle letter L and end with k  whose names retrive


"Names starts with K" — I think I understand that part.

 

"Middle letter L" — I don't know what "middle letter" means in this context

 

"End with K" — its not really clear to me what this means in this context either

 

"Retrive" — this is not a word, and even if it is a simple spelling error, it makes no sense to me in this context either

 

Please provide sample data (as working SAS data step code) and desired output. Please provide a complete and  clear explanation, and not the one-sentence explanation that you usually provide, trying to type as few words as possible. Please be generous with information and generous with your explanation.

--
Paige Miller
BrahmanandaRao
Lapis Lazuli | Level 10

 

/*scenario -1*/

data employees;
  input employee_name $;
  datalines;
John Kilkenny
Kate lark
Kristen Lockhart
Kevin lukasik
Alex King
;
run;

/*senaria-2*/

data employee;
  input name $;
  datalines;
KALAK
KILIK
KULAKzzz
;
run;

first senario- required output

 

Kate lark

Kevin lukasik

second senario-required output

KALAK KILIK

Note:ignore case  

 

 

Kurt_Bremser
Super User

In your first scenario, your INPUT statement reads only one variable, but your DATALINES contain two items each, so the second item won't appear in the dataset and can therefore not be retrieved in a later step anyway.

PaigeMiller
Diamond | Level 26

I'm afraid I can't understand what you did or why you did it. You have not EXPLAINED. You say you want middle letter 'L' but this is not explained. What do you mean by "middle letter"???

 

In addition, you have been in this community for years now, and we still have to ask you to show us some example data. This is unacceptable.  Please provide example data EVERY SINGLE TIME. Do not make us ask.

--
Paige Miller
BrahmanandaRao
Lapis Lazuli | Level 10
data employee;
  input name $;
  datalines;
KALAK
KIpplIK
KULAK
;
run;



proc sql;
  select name
  from employee
  where name like 'K%L%K';
quit;
PaigeMiller
Diamond | Level 26

I specifically asked for an explanation, not code.

 

--
Paige Miller
BrahmanandaRao
Lapis Lazuli | Level 10
data EmployeeData;
  input EmployeeName $50.;
  datalines;
kith Walkerk
Karen Clark
Mark Black
Emily Parkerk
Steve Brooks
Kelly link
;
run;

Required output with out use regex how to solve

kith Walkerk Karen Clark

Kelly link

 

ballardw
Super User

One way to create a data set with the actual values and then select those

data employees;
  infile datalines truncover;
  input employee_name $20.;
  datalines;
John Kilkenny
Kate lark
Kristen Lockhart
Kevin lukasik
Alex King
KALAK
KILIK
KULAKzzz
;
run;

data want;
   set employees;
   
   if upcase(employee_name) =:'K' 
     /*^ upper case compare  ^ "begins with"*/
    and upcase(substr(employee_name,length(employee_name),1))='K'
               /* substr function at length for 1 gets last character*/
      and find(employee_name,'L','i')>0;
          /* find letter L somewhere the 'i' is case insensitive*/
run;

"Middle" can have multiple meanings. I am taking it to mean "somewhere between first and last character" for an L.

The other bits just look at the first and last character for the K's. NOT the only way.

 

You really need to make sure that your data steps run and produce the desired result for providing example data.

 


@BrahmanandaRao wrote:

 

/*scenario -1*/

data employees;
  input employee_name $;
  datalines;
John Kilkenny
Kate lark
Kristen Lockhart
Kevin lukasik
Alex King
;
run;

/*senaria-2*/

data employee;
  input name $;
  datalines;
KALAK
KILIK
KULAKzzz
;
run;

first senario- required output

 

Kate lark

Kevin lukasik

second senario-required output

KALAK KILIK

Note:ignore case  

 

 


 

Tom
Super User Tom
Super User

Testing if the first or last character is a K is easy enough.

For example you could use FINDC().

  startK=1=findc(name,'k','i');
  lastK=length(name)=findc(name,'k',-length(name),'i');

Or just =: operator.

  startK=upcase(name)=:'K';
  lastK=upcase(reverse(strip(name)))=:'K';

Testing if there is an L anywhere the middle can be done with FINDC().

  middleL=1<findc(name,'L','i')<length(name);

Then just require that all three are true.

  want = startK and lastK and middleL ;

Of course if the first and last have to be K then you don't really care where the L is since it will NOT be the first or the last so it will be in the middle.

  want=upcase(name)=:'K'
     and upcase(reverse(strip(name)))=:'K'
     and findc(name,'L','i')
  ;
Kurt_Bremser
Super User

@BrahmanandaRao wrote:

Hi Guys,

suppose i have employees table in the table which names starts with 'K' and middle letter with 'L' and end with 'K' in employees name column


And what is your question?

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 13 replies
  • 1267 views
  • 0 likes
  • 5 in conversation