Help using Base SAS procedures

DELETE or SELECT TEXT BEGINNING WITH SAME CHARACTER

Reply
Occasional Contributor
Posts: 16

DELETE or SELECT TEXT BEGINNING WITH SAME CHARACTER

I have a variable by the name DiseaseCode. How can I select any code that begins with B2.

That is I want to select anything of the form B2**. It can be B23, B2K, B2SKH.

Can someone help.
SAS Super FREQ
Posts: 8,866

Re: DELETE or SELECT TEXT BEGINNING WITH SAME CHARACTER

Posted in reply to Statsconsultancy
Hi:
Look at the WHERE statement documentation and the LIKE operator:
http://support.sas.com/documentation/cdl/en/lrdict/63026/HTML/default/viewer.htm#a000202951.htm

For example, you could do:
[pre]
proc print data=lib.data;
where disease like 'B2%';
run;

or,

data new;
set lib.data;
where disease like 'B2%';
run;
[/pre]

For the LIKE operator, the _ (underscore) is the wild card character for 1 character and the % (percent) is the wild card character for multiple characters. So, for example, LIKE 'B2_' would find a value that started with B2 and had any 3rd character, while LIKE 'B2%' would find B2X, B2XYZ or B2ABCDEFG.

cynthia
Frequent Contributor
Frequent Contributor
Posts: 77

Re: DELETE or SELECT TEXT BEGINNING WITH SAME CHARACTER

Posted in reply to Statsconsultancy
You can also use a colon modifier to select codes that "Begin With". However, I believe that this method is limited to an "IF" statement.

see http://support.sas.com/kb/24/851.html

(Sample 24851: Using a Colon Modifier to Select Observations with Values Beginning with a Specific Character By Kirk Paul Lafler)

for more information.
Ask a Question
Discussion stats
  • 2 replies
  • 151 views
  • 0 likes
  • 3 in conversation