BookmarkSubscribeRSS Feed
Statsconsultancy
Fluorite | Level 6
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.
2 REPLIES 2
Cynthia_sas
SAS Super FREQ
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
LAP
Quartz | Level 8 LAP
Quartz | Level 8
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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 809 views
  • 0 likes
  • 3 in conversation