楼主: harlon1976
7529 7

[原创博文] 请教这个SAS程序 [推广有奖]

  • 2关注
  • 27粉丝

版主

院士

54%

还不是VIP/贵宾

-

威望
1
论坛币
33781 个
通用积分
135.1232
学术水平
25 点
热心指数
39 点
信用等级
17 点
经验
59249 点
帖子
1928
精华
0
在线时间
4352 小时
注册时间
2005-8-27
最后登录
2025-12-9

楼主
harlon1976 发表于 2006-1-3 20:08:00 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
<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>
二维码

扫码加我 拉你入群

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

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

关键词:sas程序 Expression arithmetic express output 程序 样本

回帖推荐

harlon1976 发表于4楼  查看完整内容

我已经找到错误所在,既然大家感兴趣,我就和大家说说,只需将%换为&即可,其余不动,将%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= ...

本帖被以下文库推荐

沙发
lihuang 发表于 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

藤椅
tianjfang 发表于 2006-1-9 23:52:00

我也是,出现死循环

板凳
harlon1976 发表于 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;

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

已有 1 人评分经验 论坛币 收起 理由
bakoll + 2 + 10 热心帮助其他会员

总评分: 经验 + 2  论坛币 + 10   查看全部评分

报纸
wmqy2004 发表于 2006-1-19 22:46:00
我已试过了,非常顺畅

地板
abc797260 发表于 2010-2-18 14:09:02
1# harlon1976
对于宏变量的引用:
%let a=1 %then;
%if &a.=1 %then %do;
....................
是&a.=1 不是 %a=1

7
醉_清风 发表于 2010-2-18 19:03:14
进来学习了
从来不需要想起 永远也不会忘记

8
jingju11 发表于 2010-2-19 02:21:23
1# harlon1976

Anyway, Macro is used to make the program more concise and re-usable.

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-7 08:46