全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
7451 7
2006-01-03
<P>我打算用SAS来模拟不同样本容量下样本均值的分布情况,使用下列程序:</P>
<P>%let n=10;
%macro limit;
%do a=1 %to 5;
%if %a=1 %then %do; %let smplsize=10; %end;
%if %a=2 %then %do; %let smplsize=50;  %end;
%if %a=3 %then %do; %let smplsize=100;  %end;
%if %a=4 %then %do; %let smplsize=500;  %end;
%if %a=5 %then %do; %let smplsize=1000;  %end;
%do b=1 %to &n;
data dat;
do i=1 to &smplsize;
x=ranuni(0);
x=-0.59+(x**0.0355-(1-x)**0.1179)/0.1206;
output;
end;run;
proc means data=dat;
var x;
output out=dat1 mean=meanx;run;
data dat2;
set dat1;
smplsize=&smplsize;
keep smplsize meanx;
%end;
%end;
%mend limit;
%limit;run;
提交后,LOG窗口显示:Expecting an arithmetic expression.
我百思不得其解,望高人指点迷津.</P>
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2006-1-9 22:17:00

我运行后,得到的结果为:

1 %let n=10; 2 %macro limit; 3 %do a=1 %to 5; 4 %if %a=1 %then %do; %let smplsize=10; %end; 5 %if %a=2 %then %do; %let smplsize=50; %end; 6 %if %a=3 %then %do; %let smplsize=100; %end; 7 %if %a=4 %then %do; %let smplsize=500; %end; 8 %if %a=5 %then %do; %let smplsize=1000; %end; 9 %do b=1 %to &n; 10 data dat; 11 do i=1 to &smplsize; 12 x=ranuni(0); 13 x=-0.59+(x**0.0355-(1-x)**0.1179)/0.1206; 14 output; 15 end;run; 16 proc means data=dat; 17 var x; 18 output out=dat1 mean=meanx;run; 19 data dat2; 20 set dat1; 21 smplsize=&smplsize; 22 keep smplsize meanx; 23 %end; 24 %end; 25 %mend limit; 26 %limit;run; WARNING: Apparent invocation of macro A not resolved. WARNING: Apparent invocation of macro A not resolved. WARNING: Apparent invocation of macro A not resolved. WARNING: Apparent invocation of macro A not resolved. WARNING: Apparent invocation of macro A not resolved. NOTE: Line generated by the invoked macro "LIMIT". 26 data dat; do i=1 to &smplsize; x=ranuni(0); x=-0.59+(x**0.0355-(1-x)**0.1179)/0.1206; - 22 26 ! output; end;run; proc means data=dat; var x; output out=dat1 mean=meanx;run; data dat2; 26 ! set dat1; smplsize=&smplsize; keep smplsize meanx; WARNING: Apparent symbolic reference SMPLSIZE not resolved.

ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant, a missing value, INPUT, PUT.

NOTE: The SAS System stopped processing this step because of errors. WARNING: The data set WORK.DAT may be incomplete. When this step was stopped there were 0 observations and 3 variables. NOTE: DATA statement used: real time 0.28 seconds cpu time 0.04 seconds

NOTE: No observations in data set WORK.DAT. NOTE: The data set WORK.DAT1 has 0 observations and 3 variables. NOTE: PROCEDURE MEANS used: real time 0.34 seconds cpu time 0.06 seconds

22: LINE and COLUMN cannot be determined. NOTE 242-205: NOSPOOL is on. Rerunning with OPTION SPOOL may allow recovery of the LINE and COLUMN where the error has occurred. ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant, a missing value, INPUT, PUT. WARNING: Apparent symbolic reference SMPLSIZE not resolved.

NOTE: The SAS System stopped processing this step because of errors. WARNING: The data set WORK.DAT2 may be incomplete. When this step was stopped there were 0 observations and 2 variables. NOTE: DATA statement used: real time 0.01 seconds cpu time 0.01 seconds

NOTE: Line generated by the invoked macro "LIMIT". 26 data dat; do i=1 to &smplsize; x=ranuni(0); x=-0.59+(x**0.0355-(1-x)**0.1179)/0.1206; - 22 26 ! output; end;run; proc means data=dat; var x; output out=dat1 mean=meanx;run; data dat2; 26 ! set dat1; smplsize=&smplsize; keep smplsize meanx; WARNING: Apparent symbolic reference SMPLSIZE not resolved

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2006-1-9 23:52:00

我也是,出现死循环

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2006-1-10 08:55:00

我已经找到错误所在,既然大家感兴趣,我就和大家说说,只需将%换为&即可,其余不动,将

%if %a=1 %then %do; %let smplsize=10; %end; %if %a=2 %then %do; %let smplsize=50; %end; %if %a=3 %then %do; %let smplsize=100; %end; %if %a=4 %then %do; %let smplsize=500; %end; %if %a=5 %then %do; %let smplsize=1000; %end; 改为:

%if &a=1 %then %do; %let smplsize=10; %end; %if &a=2 %then %do; %let smplsize=50; %end; %if &a=3 %then %do; %let smplsize=100; %end; %if &a=4 %then %do; %let smplsize=500; %end; %if &a=5 %then %do; %let smplsize=1000; %end;

即可,这是使用宏变量,而我不小心变成定义宏变量,大家可以试试.

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2006-1-19 22:46:00
我已试过了,非常顺畅
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2010-2-18 14:09:02
1# harlon1976
对于宏变量的引用:
%let a=1 %then;
%if &a.=1 %then %do;
....................
是&a.=1 不是 %a=1
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群