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

Hello!

 

I have 2 sets of data in SAS Studio. The 1st data set has basic customer information (customer ID, city, state, etc...) and the 2nd data set has a listing of transaction by each customer. I need to append the customer data to the transaction data using the customer ID. I've tried using the merge function, but it then narrows down the transaction information down to 1 observation.

 

data transactions;
      set CD8940.transaction_data;
run;

data customer_info;
     set CD8940.customer_info;
run;

data merged;
	merge transactions customer_info;
run;

Any help is greatly appreciated!

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

You did not provide any thing to tell the Merge to use the ID value. Which would be a BY ID statement if both sets are sorted by Id.

However Merge may run into issues with many-to-one (multiple transactions for one customer) and the order you place the data sets on a merge statement.

 

Proc SQL has many tools for combining data in interesting ways. One way:

proc sql;
   create table joined as
   select a.*, b.city, b.state
   from cd8940.transactiondata as a
        left join
        cd8940.customer_info as b
        on a.id = b.id
   ;
quit;

View solution in original post

2 REPLIES 2
ballardw
Super User

You did not provide any thing to tell the Merge to use the ID value. Which would be a BY ID statement if both sets are sorted by Id.

However Merge may run into issues with many-to-one (multiple transactions for one customer) and the order you place the data sets on a merge statement.

 

Proc SQL has many tools for combining data in interesting ways. One way:

proc sql;
   create table joined as
   select a.*, b.city, b.state
   from cd8940.transactiondata as a
        left join
        cd8940.customer_info as b
        on a.id = b.id
   ;
quit;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 772 views
  • 0 likes
  • 2 in conversation