楼主: harlon1976
15033 31

[原创博文] 提取数据集的观测数 [推广有奖]

21
gzndxf 发表于 2010-3-23 19:48:43
向高手学习

22
harlon1976 发表于 2010-3-23 20:08:26
学习在行动,心里知道就行了,请路过的同志不要以这种方式灌水。

23
soporaeternus 发表于 2010-3-23 21:18:22
17# harlon1976
rename=的语法吧
data步选项中要
data xx(rename=());
就是
rename= 的后面,那个%T1(v1,v2,n)外面还要有个括号.....
Let them be hard, but never unjust

24
harlon1976 发表于 2010-3-23 22:19:35
23# soporaeternus
这回是我粗心了,现在整个程序都能能运行了,感谢你的无私、及时、热心的帮助,的确学了不少知识,尤其是你编写的两个宏还有在keep等语句的应用,涨见识了,同时也感谢其他兄弟的热心帮助,在此一并谢过。

25
xbmy 发表于 2010-3-24 03:19:46
不错,学习学习!

26
luijb 在职认证  发表于 2010-3-24 11:07:24
data a;
input x1-x3@@;
cards;
1 2 3 7 8 8 4 5 5
1 2 2 7 8 5 7 4 2
;
run;
%macro temp(in_ds);
   %let dsid=%sysfunc(open(&in_ds,i));
   %let nobs=%sysfunc(attrn(&dsid,nlobs));
   %let rc=%sysfunc(close(&dsid));
data c;
do i=1 to &nobs;
x=normal(0);
output;
end;
proc print;
run;
%mend temp;

%temp(a);

这样就可以了。
西格玛临床统计服务工作室http://www.sigma-stat.com/,luijb@163.com

27
harlon1976 发表于 2010-3-24 20:15:30
26# luijb
谢谢你的指导,你这个程序在你第一次给出的时候我就试了,的确可行,但我编写的程序不止这些,要把它放在一个宏中就不行了,例如下面程序就不能运行了:
%macro temp(in_ds);
   %let dsid=%sysfunc(open(&in_ds,i));
   %let nobs=%sysfunc(attrn(&dsid,nobs));
   %let rc=%sysfunc(close(&dsid));
data c1;
do i=1 to &nobs;
x=normal(0);
output;
end;
proc print;
run;
%mend temp(in_ds);;
%macro ml;
data a;
input x1-x3@@;
cards;
1 2 3 7 8 8 4 5 5
1 2 2 7 8 5 7 4 2
;
%temp(a);
%mend ml;
%ml;
run;
你能否指出这个程序的错误所在,也欢迎其他高手继续指点。得到这么多人的指点,本人十分高兴。

28
jingju11 发表于 2010-3-24 21:29:59
harlon1976 发表于 2010-3-24 20:15
26# luijb
谢谢你的指导,你这个程序在你第一次给出的时候我就试了,的确可行,但我编写的程序不止这些,要把它放在一个宏中就不行了,例如下面程序就不能运行了:
%macro temp(in_ds);
   %let dsid=%sysfunc(open(&in_ds,i));
   %let nobs=%sysfunc(attrn(&dsid,nobs));
   %let rc=%sysfunc(close(&dsid));
data c1;
do i=1 to &nobs;
x=normal(0);
output;
end;
proc print;
run;
%mend temp(in_ds);;
%macro ml;
data a;
input x1-x3@@;
cards;
1 2 3 7 8 8 4 5 5
1 2 2 7 8 5 7 4 2
;
%temp(a);
%mend ml;
%ml;
run;
你能否指出这个程序的错误所在,也欢迎其他高手继续指点。得到这么多人的指点,本人十分高兴。
Unfortunately, CARDS/DATALINES cannot be used in macro because macro will not take physical lines. Therefore, probably you need to avoid using CARDS statement in macro, for example, moving outside of the macro to define the data set, replacing by FILE statement, or just using output if not too many lines.
Truly, I don’t see why you use macro in the second step. My point of view is, macro, on one hand, could be efficient; on the other hand, it would cause problem you may not be well-predicted.
By the way, I had such problem before.
JingJu

29
soporaeternus 发表于 2010-3-24 22:08:23
宏不是函数,宏只是一堆高级的“文本”
其它开发工具中关于函数、返回值的操作理念在宏和SAS语句中有时候会行不通
LZ的语句对于SAS而言就是一个data步里“嵌套”了另一个data步,对于SAS来说这是语法错误
Let them be hard, but never unjust

30
jingju11 发表于 2010-3-24 22:45:11
soporaeternus 发表于 2010-3-24 22:08
宏不是函数,宏只是一堆高级的“文本”
其它开发工具中关于函数、返回值的操作理念在宏和SAS语句中有时候会行不通
LZ的语句对于SAS而言就是一个data步里“嵌套”了另一个data步,对于SAS来说这是语法错误
呵呵。不明白。你是说macro本身是data step?你能讲详细点吗?

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

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