BookmarkSubscribeRSS Feed
olorire
Calcite | Level 5

i have two small data sets a & b. a has 1 variable and nine observations.  b has 5 variables and 1 observation. there are no commonalities between the two data sets. how can i combine the two datasets to produce a new dataset c with six variables and 9 observations? by the way i am olorire.

6 REPLIES 6
stat_sas
Ammonite | Level 13

Please provide sample data and desired output.

ballardw
Super User

It depends on how you want the values of the variables resulting. If the values from the one observation set are to only appear once then you can use a data step merge.

 

data want;

   merge a b;

run;

 

If you want all of the obeservations to have the values from the one observation set then you would want an SQL cartesian (fancy work everything in one set combined with everything in the other) join.

proc sql;

   create table want as

   select a.*, b.*

   from a join b;

quit;

olorire
Calcite | Level 5

Thanks. I have opted for the sql solution although I'm still a rookie as far as that proc is concerned.

olorire

FreelanceReinh
Jade | Level 19

Hi @olorire,

 

Would this example match your intention?

 

/* Create test datasets */

data a;
do i=1 to 9;
  output;
end;
run;

data b;
array x[5] (11:15);
run;

/* Combine the two datasets */

data want;
set a;
if _n_=1 then set b;
run;

 

@ballardw: Did you mean "from a cross join b;" (or shorter: "from a, b;") ?

 

olorire
Calcite | Level 5

Thank you very much. Your coding is appropriate and straightforward.

olorire

Astounding
PROC Star

While I normally prefer a DATA step solution, note that you can simplify the SQL solution:

 

proc sql;

create table want as select * from a, b;

quit;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 6 replies
  • 875 views
  • 6 likes
  • 5 in conversation