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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 816 views
  • 0 likes
  • 3 in conversation