DATA Step, Macro, Functions and more

Merging Data: Adding one variable repeatedly to a longer series

Reply
New Contributor
Posts: 3

Merging Data: Adding one variable repeatedly to a longer series

I have two datasets, lets call them A and B.

A is the result of a Monte Carlo simulation and has 100,000 rows - 10,000 draws of a random variable (for this example) for each of 100 IDs/subjects/whatever.

So it looks like:

Iteration ID Draw
1 1 0.073
1 2 0.987
1 3 0.487
...
2 1 0.278
2 2 0.142

etc.

I also have a data set, with these same ID numbers, and a *fixed* set of variables. I'd like to merge them such that each of the 10,000 iterations of the ID sequence gets paired with the fixed variable data set.

I think this is a fairly simple thing to do, but due to some other things running in the background, I can only manage to batch submit SAS jobs, so my usual code-tinkering techniques aren't available to me.

Will a standard Merge and By work?

For example:

data work.desired;
merge work.a work.b;
by ID;
run;

?
Super User
Posts: 10,497

Re: Merging Data: Adding one variable repeatedly to a longer series

proc sql;
create work.desired as
select work.a.iteration,work.a.draw, work.b.*
from work.a left join work.b on work.a.id=work.b.id
;
quit;

Might work for you. Sql joins often run quicker than MERGE on large data sets.
Ask a Question
Discussion stats
  • 1 reply
  • 109 views
  • 0 likes
  • 2 in conversation