楼主: suizh
1362 3

%do 和 do 等变量在宏运用中有很么差别吗?能举一个例子吗? [推广有奖]

  • 3关注
  • 2粉丝

已卖:19份资源

博士生

53%

还不是VIP/贵宾

-

威望
0
论坛币
0 个
通用积分
6.5001
学术水平
6 点
热心指数
6 点
信用等级
5 点
经验
137 点
帖子
122
精华
0
在线时间
470 小时
注册时间
2012-10-23
最后登录
2025-6-28

楼主
suizh 发表于 2013-3-16 00:09:50 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
%do 和 do 等变量在宏运用中有很么差别吗?能举一个例子吗?
二维码

扫码加我 拉你入群

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

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


沙发
hamsik11 发表于 2013-3-16 00:45:01
功能不一样的 你可以先举一个可以互相替换的例子...

藤椅
bobguy 发表于 2013-3-16 06:31:37
%do belongs to SAS macro language while do belongs to SAS data step language.

板凳
yongyitian 发表于 2013-3-16 07:25:29
Here is an example of do-loop and %do-loop in a macro.
As I understand,
%do-loop can only works in macro, but do-loop can works in both in data step and macro,
the difference is in the iteration variable i, as shown in the example.

%macro Doloop(var1=, var2=, var3=);
data test;
    do i = 1 to 5;         /*   do loop works without macro variables */
        do j = &var1 to &var2; /*   this als work since j does not need to be a macro variable */
            A=i;
            B=j;
            C=&var3;           /* macro variable is used as it is used in data step ouside macro */
           output;
        end;
    end;
    drop i;
run;

data test2;
     %do i = &var1 %to &var2;     /* %do loop works with macro variables */
        do j = &var1 to &var2;
          * A=i;    /* this line does not work,  because  i  is a macro variable */
          AA = &i+1;      /* this line works, as macro is referenced */
          BB = j;           /* use of non-macro variable */
          CC = &var3;      
          output;
        end;
     %end;
      * drop i;     /* you don't need to drop i,  */
run;
%mend;
%doloop(var1=1, var2=5, var3=99);
proc print data=test; title 'test'; run;
proc print data=test2; title 'test2'; run;
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
suizh + 1 + 1 + 1 感谢你的回复

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

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

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