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

Hello,

Is it possible to make a SAS code to lookup if a customer have bought from multiple channels.

E.g.

Order_IDCustomer nameEmailRegular shopWeb-shop
12345

James

[email protected]10
54345Phil[email protected]

0

1

84736

James[email protected]01
48273Run[email protected]10

Therefore, I want to check it if a customer (by Email), at any given time, has bought in the web-shop, also bought in the regular shop.

If this is the case. this customer should have a "1" in a new column.

In the above mentioned example James would get a 1 in the new column because he bought in both shops.

I hope you guys can help me.

Kind regards

Jens

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

How about?:

proc sql;

  create table want as

    select *,

           case when sum(Regular_shop) ge 1 and sum(Web_shop) ge 1 then 1

                else 0

           end as new_var

      from have

        group by Email

  ;

quit;

View solution in original post

3 REPLIES 3
stat_sas
Ammonite | Level 13

Hi,

Try this.

proc sql;

create table want as

select a.*,b.new_var from have a

left join

(select Customer_name, Email, case when sum(Regularshop)=1 and sum(Webshop)=1 then 1 else 0

end as new_var

from have

group by Customer_name, Email) b

on a.email=b.email;

quit;

art297
Opal | Level 21

How about?:

proc sql;

  create table want as

    select *,

           case when sum(Regular_shop) ge 1 and sum(Web_shop) ge 1 then 1

                else 0

           end as new_var

      from have

        group by Email

  ;

quit;

Jens_v
Calcite | Level 5

Thank you for the answers, it was very helpful

AI Navigator GIF.gif


Navigate AI governance with SAS tools for compliance and ethical AI practices. Try SAS Ai Navigator for free for the first six months.

Check it out on Microsoft Marketplace →

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
  • 3 replies
  • 2958 views
  • 3 likes
  • 3 in conversation