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
SAS Super FREQ

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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register 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.

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