BookmarkSubscribeRSS Feed
thryce85
Fluorite | Level 6

Practing SAS sql and curious on how to directly append another column from a seperate data set into a different data set without having a unique key to join on.  Say I table A with customers  and address in one table and Table B  has 

customers and account number . Customers is not unique (lots of Joe Smith's in the world) but I know they were added to the system  in exactly the same order  and records are in a one-to-one manner.  How do I aggregate the two into a master table?  Sure its simple so sorry for being a bother.  Thanks !!

 

what I tried

------------------------------------------ 

data d1
set sashelp.cars;
run;

 

proc sql;
/*adding column */
alter table d1
add make char;

 

/*trying to insert make values back into the table */
update d1 set make =
(select make from sashelp.cars);

 

quit;

3 REPLIES 3
Reeza
Super User
I don't know if there's a SQL construct to do that, but there is in data step - MERGE without a BY statement.

data want;
merge d1 cars(keep=make);
run;
thryce85
Fluorite | Level 6
awesome thanks for the info
Tom
Super User Tom
Super User

SQL is a relational algebra.  So you need some RELATION to have it operate.

It has no way to refer to an observation by POSITION in the dataset, so there is no way in a pure SQL dialect you could combine data without some values to match on.

 

But a SAS data step will process the data from a dataset sequentially. You can just set the two datasets together.

 

data want;
  set d1;
  set sashelp.cars(keep=make);
run;

PS Using separate steps to "add" a variable to a dataset and populate the values makes no sense from a performance point of view. 

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