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

James.adams@gmail.com10
54345PhilPil@ah.uk

0

1

84736

JamesJames.adams@gmail.com01
48273RunRunner@anr.eu10

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

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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