macros - How to use cycles in sas macro data step
问题描述
I need to use cycles in a sas macro that writes a data step
I have a code that should work but it doesn't. How can i fix it?
%macro ci;
data
%do i=1 %to 3;
_z%sysfunc(putn(%eval(&i),z2.)) ;
%end;
;
set _06;
%do i=1 %to 3;
if num="%sysfunc(putn(%eval(&i),z2.))" then output _z%sysfunc(putn(%eval(&i),z2.));
%end;
run;
%mend;
%ci;
I'd like to get the following output:
data
_z01
_z02
_z03;
set _06 ;
if num="01" then output _z01;
if num="02" then output _z02;
if num="03" then output _z03;
run;
解决方案
You are very close. You simply had an extra ;
in your first loop.
You need to change:
data
%do i=1 %to 3;
_z%sysfunc(putn(%eval(&i),z2.)) ;
%end;
;
to:
data
%do i=1 %to 3;
_z%sysfunc(putn(%eval(&i),z2.))
%end;
;
Adding option mprint;
to the beginning of your code would show you the code that was generated from your macro statement and helped you to debug it.
推荐阅读
- html - 无法删除表格中的填充
- javascript - 空元素和 getElementsByClassName
- gradle - 如何使用 c 插件在 gradle 中构建 emcc
- wordpress - 由于 .htaccess 文件中的代码,Wordpress 站点搜索功能无法正常工作
- php - cookie设置但不显示在另一个页面php
- python - 如何使用 django 基于类的通用视图添加最喜欢的文章标记系统?
- python-3.x - 在 tkinter 库中看不到 GUI
- jquery-isotope - 如何使用同位素过滤器和自举手风琴?
- emulation - 拥有多个调色板的 GameBoy 有什么意义?
- tensorflow - 张量流中张量的 _keras_shape 和 _shape 有什么区别?