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

Hello,

I have one dataset that contains 1,000 observations and 50 variables - Data A.

I also have another dataset with only one observation and 30 variables - Data B.

The variables in Data B are parmeters that I want to add to all observations in Data A.

I tried to merge/set the two datasets but it only gives me first observation in A with the 1 observation in B and the other observations with missing value.

As You can see in the photo, Data A ends with variable P1000 and Data B starts with variable SM.

My question is, How do I dulplicate the one observation in B so all the observations in A will have it as a variable?

 

Thanks,

Matan.  

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

To add one observation in B to all observations in A:

 

data want;

if _n_=1 then set B;

set A;

run;

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26
Do the merge using a BY statement.
--
Paige Miller
Greisas
Fluorite | Level 6
Hi,
Thanks for the quick comment.
The problem is that Data A contains ID's, but Data B doesn't, so I can't use the BY statement.
Anyway, Astounding gave me a way.
Thanks again.
Astounding
PROC Star

To add one observation in B to all observations in A:

 

data want;

if _n_=1 then set B;

set A;

run;

Greisas
Fluorite | Level 6
Hi,
Thank you for the quick and helpful comments!

Kurt_Bremser
Super User

Consider these two methods:

data a;
input var1 var2 var3;
cards;
1 2 3
4 5 6
7 8 9
;
run;

data b;
input var4 var5;
cards;
10 11
;
run;

data want1;
set a;
_x_ = 1;
set b point=_x_;
run;

proc sql;
create table want2 as
select * from a,b;
quit;

The point=method rereads dataset b in every iteration, and therefore overrides the problem caused by the automatic "set to missing" that happens at the start of a datastep iteration.

SQL will always build a cartesian product on its own.

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
  • 5 replies
  • 4185 views
  • 7 likes
  • 4 in conversation