Help using Base SAS procedures

=;

Reply
Regular Contributor
Posts: 204

=;

Hello everyone,

If i want keep name start with 'D'. the code below works,but how if I want keep the name end with "y"?or second letter is "o"? Is there any similar operator like "=: "to do this in data step?(data step only)

data test;

  input name $;

  cards;

  John

  Diana

  Diane

  Sally

  Doug

  David

  ;

  run;

  data test;

  set test;

  if name =: 'D';

  run;

  proc print;

  run;

Thanks

Respected Advisor
Posts: 3,777

Re: =;

data test;
   set test;
   if name =: 'D' or char(name,2) eq 'o' or char(name,length(name)) eq 'y';
  
run;
Super Contributor
Posts: 426

Re: =;

data test;

  input name $;

  cards;

  John

  Diana

  Diane

  Sally

  Doug

  David

   ;

  run;

  proc sql;

create table want as select * from test where name like  '%y' or  name like '%o%' ;

quit;

  

  proc print;

  run;

Super User
Posts: 9,676

Re: =;

data test;
  input name $;
  cards;
  John
  Diana
  Diane
  Sally
  Doug
  David
  ;
  run;
  data want;
   set test;
   if prxmatch('/^D|^[a-z]o|y$/i',strip(name));
run;

Xia Keshan

Message was edited by: xia keshan

Trusted Advisor
Posts: 1,128

Re: =;

data test;
   set test;

  if substr(compress(lowcase(name)),2,1)='o' or                substr(compress(lowcase(name)),length(name),1)='y' or

     substr(compress(lowcase(name)),1,1)='d' ;

run;

Thanks,
Jag

Thanks,
Jag
Ask a Question
Discussion stats
  • 4 replies
  • 220 views
  • 0 likes
  • 5 in conversation