全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
1371 3
2013-03-16
%do 和 do 等变量在宏运用中有很么差别吗?能举一个例子吗?
二维码

扫码加我 拉你入群

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

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

全部回复
2013-3-16 00:45:01
功能不一样的 你可以先举一个可以互相替换的例子...
二维码

扫码加我 拉你入群

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

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

2013-3-16 06:31:37
%do belongs to SAS macro language while do belongs to SAS data step language.
二维码

扫码加我 拉你入群

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

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

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;
二维码

扫码加我 拉你入群

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

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

栏目导航
热门文章
推荐文章

说点什么

分享

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