BookmarkSubscribeRSS Feed
DLF22
Calcite | Level 5

Hi,

 

I am very new to sas an trying to search within a concatenated var ("COMBINATION") which is in the form (product1 + product2 + product 3) for any part of the previously used combination.  I am trying to establish how many changes in combinations are a complete change (vs an addition to an existing regimen);

 

data completley_new_products;

set combination_products;

by cust_id combination;

lag_combination= lag(combination);

where combination not contains lag_combination;

run;

 

Any help or guidance much appreciated!

 

2 REPLIES 2
andreas_lds
Jade | Level 19

It is not clear what you have and what you expect as result. So please follow the guidelines and include data in usable form, see How to convert datasets to data steps for details.

s_lassen
Meteorite | Level 14

You will probably have to split the new combination into the various product codes, and check them one by one, something like:

data completely_new_products;
  set combination_products;
  by cust_id combination;
  lag_combination= lag(combination);
  if not first.cust_id then do _N_=1 to countw(combination);
    if indexw(lag_combination,scan(combination,_N_)) then
      delete;
    end;
run;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 2 replies
  • 547 views
  • 0 likes
  • 3 in conversation