-2

enter image description here

enter image description here

  1. Table1 has Col1 and Col2
  2. Table2 is distinct Col1 as Col3 and generated random variable Col4
  3. Simulate a function Col2*2 + Col4 where Col4 is based on Table1.Col1 = Table2.Col3
  4. Col4 is diff for each trial
  5. I don't really know how to do this but tried the below. Any help will be really appreciated.

Code:

data monte_carlo;
%let num = 10;
do i = 1 to #
    do while(not eof);
        set Table2 end=eof;
        Col4 = rand('uniform'); 
        put Col4;
    end;
    do while(not eof);
        set Table1 end=eof;
        Col2*2 + Col4;
    end;
end;
run;
Reeza
  • 20,510
  • 4
  • 21
  • 38
  • Please post what you have tried first and we can help answer the questions – Stu Sztukowski Mar 05 '21 at 14:16
  • how do i post codes properly? they are getting wrapped into sentences – user13812765 Mar 08 '21 at 07:26
  • 1
    I would recommend reading this article on Stack Overflow Markdown Editing: https://stackoverflow.com/editing-help – Stu Sztukowski Mar 08 '21 at 14:49
  • I highly recommend reading [Don't be Loopy](https://support.sas.com/resources/papers/proceedings/proceedings/forum2007/183-2007.pdf) and then come back to us if that doesn't answer your questions. – Joe Mar 08 '21 at 20:47
  • 1. Merge your data so you have them in the same table. 2. Then re-try your calculation. This is just a lookup problem at the end of the day. – Reeza Mar 08 '21 at 22:28

1 Answers1

0

First, get it working for a single iteration, forgot the multiple iterations. Here's one way to do it for a single iteration.

proc sort data=table1; by col1;
proc sort data=table2; by col3;

data want;
merge table1 table2(rename =(col3=col1));
by col1;

value = col4+ col2*2;
run;

Then you figure out how to loop it. You can do that with either multiple macro calls, which is the R/Python way typically (multiple function/api calls) or the BY group way, which @Joe has linked to above Don't Be Loopy. First you have to get your base case working though.

Untested because I won't type out your data, please provide data as text not images in the future.

Reeza
  • 20,510
  • 4
  • 21
  • 38