楼主: jsuper1261
1256 5

[问答] 求教关于宏变量的问题 [推广有奖]

  • 0关注
  • 0粉丝

本科生

94%

还不是VIP/贵宾

-

威望
0
论坛币
40 个
通用积分
0
学术水平
1 点
热心指数
1 点
信用等级
0 点
经验
3265 点
帖子
83
精华
0
在线时间
110 小时
注册时间
2012-8-20
最后登录
2025-2-26

楼主
jsuper1261 发表于 2012-10-22 09:48:58 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
name=dsn, n=1
想得到dsn1
是&name&n ,&name.&n ,&&name.&n 中哪一个呢?

还有,想生成dsn1 dsn2 dsn3 dsn4 dsn5,下面这个程序怎么出错呢?
%macro names(name= ,number= );
   %do n=1 %to &number;
      &name&n
   %end;
%mend names;
%names(name=dsn,number=5)

NOTE: 由宏变量 N 生成行。
1     dsn1
      ----
      180
ERROR 180-322: 语句无效或未按正确顺序使用。



其实上面的都是sas 9.2 macro language reference 第9页的内容。
二维码

扫码加我 拉你入群

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

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

关键词:Reference Language Number erence Names amp 程序 number names

沙发
bobguy 发表于 2012-10-22 10:25:38
The macro is a text generator. Your macro generates dsn1,...,dsn5.

When you use it, the generated codes should follow SAS syntax. Here is the correct way to use it. See below,


1    %macro names(name= ,number= );
2       %do n=1 %to &number;
3          &name&n
4       %end;
5    %mend names;
6
7    data %names(name=dsn,number=5) ;
8      x=1;
9    run;

NOTE: The data set WORK.DSN1 has 1 observations and 1 variables.
NOTE: The data set WORK.DSN2 has 1 observations and 1 variables.
NOTE: The data set WORK.DSN3 has 1 observations and 1 variables.
NOTE: The data set WORK.DSN4 has 1 observations and 1 variables.
NOTE: The data set WORK.DSN5 has 1 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           0.04 seconds
      cpu time            0.01 seconds

藤椅
jsuper1261 发表于 2012-10-22 10:44:06
bobguy 发表于 2012-10-22 10:25
The macro is a text generator. Your macro generates dsn1,...,dsn5.

When you use it, the generate ...
哦,谢谢。

那第一个问题呢?
&name&n ,&name.&n ,&&name.&n这3个有区别吗

我总觉得,&name&n会被解析成&name1吗。。

板凳
jsuper1261 发表于 2012-10-22 15:56:47
这3个木有区别

报纸
jsuper1261 发表于 2012-10-22 15:59:17
如果是&&name&n就不同拉

地板
bobguy 发表于 2012-10-23 10:53:33
jsuper1261 发表于 2012-10-22 10:44
哦,谢谢。

那第一个问题呢?
Q: &name&n ,&name.&n ,&&name.&n这3个有区别吗?
A: In this context they are the same. ---> dsn5;

Q: 我总觉得,&name&n会被解析成&name1吗。。
A: &name&n  = resoved &name || resoved &n = dsn5
  SAS resolves process for a macro variable         &&name&n   1)  &&-->&      and &n --->5
                                                                                         2) &name5  ---> the value of macro variable of name5. If the variable is not defined, SAS macro facility will issue a warning message.


已有 1 人评分学术水平 热心指数 信用等级 收起 理由
jsuper1261 + 1 + 1 + 1 热心帮助其他会员

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

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-24 19:34