BookmarkSubscribeRSS Feed
div44
Calcite | Level 5

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

 

3 REPLIES 3
art297
Opal | Level 21

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

ChrisNZ
Tourmaline | Level 20

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

 

Oligolas
Barite | Level 11

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

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 -

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 695 views
  • 2 likes
  • 4 in conversation