DATA Step, Macro, Functions and more

Use of colon (:) in editor window

Reply
Contributor
Posts: 21

Use of colon (:) in editor window

A dataset "want" has 4 variables car1, car2, car3, car4. I want to see if any of the 4 variables have values 5,6,7,8 in them.

 

data need;

set want;

if car: in (5,6,7,8) then output;

run;

 

Error at car: 

ERROR 22-322: Syntax error, expecting one of the following: <, <=, =, >, >=, EQ, GE, GT, LE, LT, NE, NG, NL, ^=, ~=.

 

How do I use all four variables without writing each one of them in the code

 

Thank you

 

PROC Star
Posts: 7,467

Re: Use of colon (:) in editor window

Here is one way:

data have;
  input car1-car4;
  cards;
1 3 4 9
1 5 2 2
5 2 3 7
;

data want;
set have;
  array cars car:;
  do i=1 to dim(cars);
    if cars(i) in (5,6,7,8) then do;
      output;
      leave;
    end;
  end;
run;

Art, CEO, AnalystFinder.com

PROC Star
Posts: 1,759

Re: Use of colon (:) in editor window

Here is another way:

data HAVE;
  input CAR1-CAR4;
  cards;
1 3 4 9
1 5 2 2
5 2 3 7
;

data WANT;
  set HAVE;
  MATCH= prxmatch('/[5678]/',catt(of CAR1-CAR4)) > 0 ;
run;
CAR1 CAR2 CAR3 CAR4 MATCH
1 3 4 9 0
1 5 2 2 1
5 2 3 7 1

 

Frequent Contributor
Posts: 129

Re: Use of colon (:) in editor window

it's a bit like taking a sledgehammer to crack a nut but I like that Smiley Happy

I would have done nearly the same as @art297 demonstrated

 

data want;
  set have;
  array cars car:;
  do over cars;
    if cars in (5,6,7,8) then Flag=1;
  end;
run;

Cheers

________________________

- Cheers -

Ask a Question
Discussion stats
  • 3 replies
  • 117 views
  • 2 likes
  • 4 in conversation