Help using Base SAS procedures

Operators

Reply
Super Contributor
Posts: 1,041

Operators

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

Super User
Super User
Posts: 7,050

Re: Operators

Posted in reply to robertrao

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%' ;


Super Contributor
Posts: 1,041

Re: Operators

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 =varSmiley Happy

how is this:

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

SAS Super FREQ
Posts: 8,866

Re: Operators

Posted in reply to robertrao

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 (Smiley Happy 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;

Ask a Question
Discussion stats
  • 3 replies
  • 137 views
  • 3 likes
  • 3 in conversation