【发布时间】:2018-11-06 20:08:01
【问题描述】:
您好,我正在尝试使用 do 循环和 if 语句编写宏函数。我想我搞砸了 if-then do 和 do 循环,我无法找出问题所在。 我有一张儿童信息表,其中包含年龄、性别、运动、乐器等列。
我的原始代码如下所示:
data old;
set new;
if sports in ("football","basketball") and age <=7 then type =1;
else if sports='swimming' then type=2;
if special_kid=. then do;
if piano ^=. and piano_1 ^=. then do; talent_type=1; type_name=piano_1; end;
if violin ^=. and violin_1 ^=. then do; talent_type=1; type_name=violin_1; end;
end;
run;
我有一堆要编辑类型和名称的乐器。我想写一个循环来自动完成,但我不确定为什么下面的代码不起作用。
%let instrm = piano violin;
%macro my_func;
data old;
set new;
%if sports in ("football","basketball") and age <=7 %then type =1;
%else %if sports='swimming' %then type=2;
%do %while (special_kid=.);
%do i % to sysfunc(countw(&instrm));
%let word = %scan(&name, &i);
%if &word ^=. and ^word._1 ^=. %then %do;
talent_type=1; type_name=&word._1;
%end;
%end;
%end;
run;
%mend;
它总是给我错误
ERROR: An unexpected semicolon occurred in the %DO statement.
ERROR: A dummy macro will be compiled.
谁能回答我的问题?谢谢!
【问题讨论】:
-
这将有助于显示您的输入数据和预期输出。
-
一般来说,如果你想将相同的过程应用于不同的变量,使用数组比使用宏更容易。
-
数据是什么样的?变量
piano和piano_1是什么意思?
标签: loops if-statement sas sas-macro