RANUNI函数在SAS中。

huangapple go评论69阅读模式
英文:

RANUNI Function in SAS

问题

我想解决的问题是在一个DO循环中使用RANUNI,并调用生成10个样本,每个样本大小为15,随机变量的值是介于10和20之间的数字。由于我必须使用调用例程,我无法获得介于10和20之间的变量。在拥有以下代码之后,我生成了0到1之间的值。

到目前为止,我已经做了这个-

DATA seven;
DO i=1 TO 15;
 CALL RANUNI(2020, x1);
 CALL RANUNI(2020, x2);
 CALL RANUNI(2020, X5);
 CALL RANUNI(2020, X6);
 CALL RANUNI(2020, X7);
 CALL RANUNI(2020, X8);
 CALL RANUNI(2020, x3);
 CALL RANUNI(2020, x4);
 CALL RANUNI(2020, x9);
 CALL RANUNI(2020, x10);
 OUTPUT;
END;
PROC PRINT DATA=SEVEN NOOBS ;
RUN;
```

<details>
<summary>英文:</summary>

I want a solution to the problem where I have to use the RANUNI in a DO loop and call, and generate 10 samples, each of size 15, the value of the random variable is a number between 10 and 20.  
Since I have to use Call Routine, I am not able to get variables between 10 and 20. After having the following code, I am generating values between 0 to 1.  

So far I have done this-

DATA seven;
DO i=1 TO 15;
CALL RANUNI(2020, x1);
CALL RANUNI(2020, x2);
CALL RANUNI(2020, X5);
CALL RANUNI(2020, X6);
CALL RANUNI(2020, X7);
CALL RANUNI(2020, X8);
CALL RANUNI(2020, x3);
CALL RANUNI(2020, x4);
CALL RANUNI(2020, x9);
CALL RANUNI(2020, x10);
OUTPUT;
END;
PROC PRINT DATA=SEVEN NOOBS ;
RUN;


</details>


# 答案1
**得分**: 2

使用 [`CALL STREAMINIT`](https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p0gw58qo85qp56n1kbpiz50ww8lv.htm) 例程与 [RAND()](https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p0fpeei0opypg8n1b06qe4r040lv.htm) 函数

```sas
data want;
call streaminit(2120);

do sample=1 to 10;
	do obs=1 to 15;
		rand=rand('uniform', 10, 20);
		output;
	end;
end;

drop obs;
run;
sample    rand
  1    14.767593681
  1    13.535240577
  1    12.954676473
  1    10.660713173
  1    13.894441081
  1    10.843995532
 ...       ...
 10   13.716131395
 10   13.261181149
 10   17.789552165
英文:

Perhaps use the CALL STREAMINIT routine with the RAND() function

data want;
call streaminit(2120);

do sample=1 to 10;
	do obs=1 to 15;
		rand=rand(&#39;uniform&#39;, 10, 20);
		output;
	end;
end;

drop obs;
run;
sample    rand
  1    14.767593681
  1    13.535240577
  1    12.954676473
  1    10.660713173
  1    13.894441081
  1    10.843995532
 ...       ...
 10   13.716131395
 10   13.261181149
 10   17.789552165

huangapple
  • 本文由 发表于 2023年2月24日 16:23:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/75554149.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定