BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Tal
Pyrite | Level 9 Tal
Pyrite | Level 9

based on the crieria below i need to get a "want" table such as this one below but     cuz of the (product_type=n and prod_code ne l)

the client with id=102 gets placed in the group=100 and he is not supposed to as he also has a code=l

data have;

input id prod_type $ prod_code $ ;

cards;

100 a b

101 a b

101 c s

102 n v

102 n l

103 n v

103 n j

105 a d

106 v d

107 g t

;

data want;

set have;

if prod_type in(a,c) or

   prod_code=d       or

   (product_type=n and prod_code ne l) then group=100 ;run;

want:

id prod_type prod_code group ;

100 a b    100

101 a b    100

101 c s    100

102 n v

102 n l

103 n v    100

103 n j    100

105 a d    100

106 v d    100

107 g t

and  ths is  what i get

id prod_type prod_code group ;

100 a b    100

101 a b    100

101 c s    100

102 n v    100

102 n l

103 n v    100

103 n j    100

105 a d    100

106 v d    100

107 g t

How do i fix this ,anyone please?

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

Below code should do:

data have;

input id prod_type $ prod_code $ ;

cards;

100 a b

101 a b

101 c s

102 n v

102 n l

103 n v

103 n j

105 a d

106 v d

107 g t

;

run;

%let cond=prod_code='d' or prod_type in ('a','c') or (prod_type='n' and prod_code ne 'l');

data want(drop=_:);

  set have;

  if _n_=1 then

    do;

      dcl hash h1(dataset:"have(where=(not (&cond)))");

      _rc=h1.defineKey('id');

      _rc=h1.defineDone();

    end;

  if h1.check() ne 0 then group=100;

run;

View solution in original post

2 REPLIES 2
Patrick
Opal | Level 21

Below code should do:

data have;

input id prod_type $ prod_code $ ;

cards;

100 a b

101 a b

101 c s

102 n v

102 n l

103 n v

103 n j

105 a d

106 v d

107 g t

;

run;

%let cond=prod_code='d' or prod_type in ('a','c') or (prod_type='n' and prod_code ne 'l');

data want(drop=_:);

  set have;

  if _n_=1 then

    do;

      dcl hash h1(dataset:"have(where=(not (&cond)))");

      _rc=h1.defineKey('id');

      _rc=h1.defineDone();

    end;

  if h1.check() ne 0 then group=100;

run;

Tal
Pyrite | Level 9 Tal
Pyrite | Level 9

dont know hash tables but this really works Smiley Happy

Thanks a lot Patrick

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
  • 2 replies
  • 659 views
  • 1 like
  • 2 in conversation