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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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