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;

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
  • 2 replies
  • 517 views
  • 0 likes
  • 2 in conversation