Macros 带有长度语句的SAS宏代码错误
我试图根据我拥有的列表更改变量的长度,代码似乎可以工作,但没有达到预期的输出。代码如下:Macros 带有长度语句的SAS宏代码错误,macros,sas,Macros,Sas,我试图根据我拥有的列表更改变量的长度,代码似乎可以工作,但没有达到预期的输出。代码如下: %macro LEN(); Proc sql ; select count(name) into: varnum from variab; select name into: varname1-:varname%trim(%left(&varnum)) from Variab; select length3 into: len from Length; Quit; %do i=1
%macro LEN();
Proc sql ;
select count(name) into: varnum from variab;
select name into: varname1-:varname%trim(%left(&varnum)) from Variab;
select length3 into: len from Length;
Quit;
%do i=1 %to &varnum;
data Zero;
length &&varname&i $ &&len&i.;
set desti.test;
length _numeric_ 4.;
format _numeric_ 12.2;
run;
%end;
%mend;
它给出了一个警告
WARNING: Multiple lengths were specified for the variable fscadl1 by
input data set(s). This can cause truncation
of data.
它不会改变变量的长度。这个代码有什么问题 警告消息表明它正在工作。SAS在截断变量时开始抛出该警告。可以使用VARLENCHK选项抑制警告消息 以下工作:
options varlenchk=nowarn;
data want;
length name $ 3;
set sashelp.class;
length _numeric_ 4;
run;
如果您的代码不起作用,我会打开MPRINT以确保您的宏正在生成您期望的SAS代码。是否尝试更改一个数据集中的变量列表?您正在为每个迭代重复整个数据步骤,但只写入一个恒定的目标,这是不一致的 也许你想要的是:
Proc sql ;
select count(name) into: varnum from variab;
select name into: varname1-:varname%trim(%left(&varnum)) from Variab;
select length3 into: len from Length;
Quit;
%macro set_len(varnum=);
%do i=1 %to &varnum;
length &&varname&i $ &&len&i.;
%end;
%mend;
data Zero;
%set_len(&varnum);
set desti.test;
length _numeric_ 4.;
format _numeric_ 12.2;
run;
请注意,您需要定义
和&len&i
,因为您目前没有这样做。所需的输出是什么?你能发布简单的输入/输出数据吗?