BookmarkSubscribeRSS Feed
robertrao
Quartz | Level 8

where category variable has :

in

out

middle

Are these both notations correct to select all the value starting with in???
if category eq: "in" then....

if category eq "in:" then....

Thanks

3 REPLIES 3
Tom
Super User Tom
Super User

The colon is a modifier on the comparison operator, not on the value.

if category eq: "in" then ...


If you are using WHERE instead of IF then you could use LIKE operator:


where category like 'in%' ;


robertrao
Quartz | Level 8

i was confused because we use colon operator beisde variable name to pick the variable names starting with the specified

like

if we have variables var1 to var50

we can just write for example( keep =var:)

how is this:

if category eq: "in" then ... different from the above????

Cynthia_sas
Diamond | Level 26

Hi,

Take a look at this: 24851 - Using a Colon Modifier to Select Observations with Values Beginning with a Specific Characte... or from the doc (SAS(R) 9.3 Language Reference: Concepts, Second Edition) "You can add a colon (:) modifier to any of the operators to compare only a specified prefix of a character string."

Or, you can write a program to prove to yourself how the different syntax elements would work.

cynthia

data colon_mod;

  infile datalines;

  input string $;

  test1 = 'n';

  test2 = 'n';

  test3 = 'n';

  if string =: 'in' then test1 = 'y';

  if string =  'in' then test2 = 'y';

  if string = 'in:' then test3 = 'y';

return;

datalines;

inert

input

in

inagadda

nothing

;

run;

  

ods listing;

proc print data=colon_mod;

run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 3 replies
  • 1270 views
  • 3 likes
  • 3 in conversation