SAS模拟随机变量 [英] SAS simulate with random variable

查看:68
本文介绍了SAS模拟随机变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  1. 表1具有Col1和Col2
  2. Table2与Col3不同,是Col1,并生成了随机变量Col4
  3. 模拟一个函数Col2 * 2 + Col4,其中Col4基于Table1.Col1 = Table2.Col3
  4. 每个试验的Col4差异
  5. 我真的不知道该怎么做,但尝试了以下方法.任何帮助将不胜感激.

代码:

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;

推荐答案

首先,让它只能进行一次迭代,而忘记了多次迭代.这是一次迭代的一种方法.

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;

然后您便知道如何循环播放它.您可以使用多个宏调用(通常是R/Python方式(多个函数/api调用))或BY组方式(通过@Joe链接到上面的不要循环")来做到这一点.首先,您必须使基本情况起作用.

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.

这篇关于SAS模拟随机变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆