全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
2852 10
2012-11-10
%macro name;
data _null_;
array r(2) x y (1,2);
%mend name;
%name;


试了一下上面的例子……貌似不行T_T……

二维码

扫码加我 拉你入群

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

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

全部回复
2012-11-10 19:39:46
哦,路过
二维码

扫码加我 拉你入群

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

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

2012-11-10 21:13:46
Why not?

1    %macro name;
2    data _null_;
3    array r(2) x y (1,2);
4    %mend name;
5    %name
6    run;

NOTE: DATA statement used (Total process time):
      real time           0.12 seconds
      cpu time            0.01 seconds


The better one would be a run statement with it.
%macro name;
data _null_;
    array r(2) x y (1,2);
run;
%mend name;
%name
二维码

扫码加我 拉你入群

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

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

2012-11-10 21:57:40
bobguy 发表于 2012-11-10 21:13
Why not?

1    %macro name;
I'm sorry I have misunderstood that. But I can't apply the dim() function in the macro. I can't figure out why. Would you help me to solve this problem? I'm a green hand in this area and I can't thank you more^^
data _null_;
set d1;
array  _allvar_(*) _all_;
do i=1 to dim(_allvar_);
vname=vname(_allvar_(i));
put vname=;
end;
run;



%macro name;
data d1;
set d1;
array  _allvar_(*) _all_;
%do i=1 %to dim(_allvar_);
vname=vname(_allvar_(i));
put vname=;
%end;
run;
%mend name;
%name;

The error is:

ERROR: 需要的操作符在以下表达式中没有找到: dim(_allvar_)
ERROR: %TO 值(%DO I 循环中)无效。
ERROR: 宏 NAME 将终止执行。

I'm a little confused with the macro application now...Actually, my attempt was to change the names of a dataset to v1-v5. The original names may not follow a fornula, for example, like  "id name age address phone" and so on. How can I program it by the macro method? Thank you !
二维码

扫码加我 拉你入群

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

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

2012-11-11 00:23:45
若水烟寒 发表于 2012-11-10 21:57
I'm sorry I have misunderstood that. But I can't apply the dim() function in the macro. I can't fi ...
You misunderstand the macro loop and data step loop. It is hugely different between them.

Please change the looping as the example below.

2165  data d1;
2166    retain x c v b avcd 0;
2167   run;

NOTE: The data set WORK.D1 has 1 observations and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


2168
2169  %macro name;
2170  data d1;
2171  set d1;
2172  array  _allvar_(*) _all_;
2173  do i=1 to dim(_allvar_);
2174  vname=vname(_allvar_(i));
2175  put vname=;
2176  end;
2177  run;
2178  %mend name;
2179  %name;

vname=x
vname=c
vname=v
vname=b
vname=avcd
NOTE: There were 1 observations read from the data set WORK.D1.
NOTE: The data set WORK.D1 has 1 observations and 7 variables.
NOTE: DATA statement used (Total process time):
      real time           0.06 seconds
      cpu time            0.01 seconds
二维码

扫码加我 拉你入群

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

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

2012-11-11 00:29:58
bobguy 发表于 2012-11-10 21:13
Why not?

1    %macro name;
why is this better?can you explain it?
二维码

扫码加我 拉你入群

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

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

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

说点什么

分享

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