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

Dear all,

 

I'm trying to merge two datasets, but I have some questions about that.

One of the two datasets (have1) includes only one row, like the following:

A       B

3.2    1.2

And the other dataset (have2) has three variables with lots of observations like this:

X   Y   Z

2   3    1

6   3    1

3   3    1

... ...

The final dataset I want to output is:

X   Y   Z   A      B

2   3    1  3.2   1.2

6   3    1  3.2   1.2

3   3    1  3.2   1.2

... ...        3.2   1.2

 

If I use:

data want;

merge have1 have2;

run;

The result I got includes only the first row with the values of A and B, the others are all missing value.

I know I could directly use 

data want;  set have2;

A=3.2;

B=1.2;

run;

However, I'm writing a macro, and there has thousands datasets I want to do so, therefore it's not possible to do this.

 

Hope anyone can help me about this. Thank you!

 

Best,

Hua

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

https://github.com/statgeek/SAS-Tutorials/blob/master/add_average_value_to_dataset.sas

 

The first example here is relevant, it shows how to merge in the single row of data.

View solution in original post

4 REPLIES 4
Reeza
Super User

https://github.com/statgeek/SAS-Tutorials/blob/master/add_average_value_to_dataset.sas

 

The first example here is relevant, it shows how to merge in the single row of data.

hua
Obsidian | Level 7 hua
Obsidian | Level 7
Yes! It is exactly what I want!
Thank you!!!
SuryaKiran
Meteorite | Level 14

Hi,

 

SQL Cartesian product solves your problem.

 

Simply: 

proc sql;
create table need as
select * from have2,have1;
quit;

Thanks,
Suryakiran
hua
Obsidian | Level 7 hua
Obsidian | Level 7
Right! It also works well! Thank you for your reply and help!

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
  • 4 replies
  • 833 views
  • 2 likes
  • 3 in conversation