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;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2 replies
  • 384 views
  • 0 likes
  • 2 in conversation