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
Diamond | Level 26
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.

Catch up on SAS Innovate 2026

Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.

Explore Now →
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.

SAS Training: Just a Click Away

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

Browse our catalog!

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