楼主: 若水烟寒
2951 10

请问在宏之中可以定义array嘛? [推广有奖]

  • 3关注
  • 9粉丝

已卖:840份资源

博士生

8%

还不是VIP/贵宾

-

威望
0
论坛币
1391 个
通用积分
33.0863
学术水平
14 点
热心指数
18 点
信用等级
12 点
经验
2716 点
帖子
183
精华
0
在线时间
176 小时
注册时间
2011-5-11
最后登录
2025-6-4

楼主
若水烟寒 发表于 2012-11-10 19:34:34 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
%macro name;
data _null_;
array r(2) x y (1,2);
%mend name;
%name;


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

二维码

扫码加我 拉你入群

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

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

关键词:array ARR Ray Macro name null

沙发
haororyfy 发表于 2012-11-10 19:39:46
哦,路过

藤椅
bobguy 发表于 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 !

报纸
bobguy 发表于 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?

7
bobguy 发表于 2012-11-11 01:14:26
龙潭丰乐 发表于 2012-11-11 00:29
why is this better?can you explain it?
Do you see the difference?

8
若水烟寒 发表于 2012-11-11 08:59:10
bobguy 发表于 2012-11-11 00:23
You misunderstand the macro loop and data step loop. It is hugely different between them.

Pleas ...
Thank you very much. But I want to use the macro variables such as "&**" in the macro loop because I want to change the variable names in large quantities. And the data loop can't do that job with the macros T_T....So I really want to know why I can't use the function like dim() in the macro loop....

9
若水烟寒 发表于 2012-11-11 09:00:03
bobguy 发表于 2012-11-11 01:14
Do you see the difference?
He changes "%do %to %end" to "do to end"

10
bobguy 发表于 2012-11-11 10:09:53
若水烟寒 发表于 2012-11-11 08:59
Thank you very much. But I want to use the macro variables such as "&**" in the macro loop because ...
Here is a general example for rename variable in a data set.


DATA TMP;
   retain xc n jsa NNGVCHJ 'ABC';
   retain J K HDY  G DB  B 0;
RUN;

PROC PRINT;RUN;

****RENAME BEGIN WITH _;

PROC SQL NOPRINT;
  SELECT CATX(' ', 'RENAME',NAME,'=', CATT('_',NAME),';')
         INTO: RENAMEST SEPARATED BY ' '
  FROM DICTIONARY.COLUMNS
  WHERE LIBNAME='WORK' AND MEMNAME='TMP';
  QUIT;

PROC DATASETS LIB=WORK;
MODIFY TMP;
&RENAMEST
QUIT;

PROC PRINT;RUN;
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
若水烟寒 + 1 + 1 + 1 热心帮助其他会员

总评分: 学术水平 + 1  热心指数 + 1  信用等级 + 1   查看全部评分

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

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