我有两个数据集,一个标准集一个测试集。里面的变量名是一样的,但是有几个变量的类型不一样,现在想追加成一个数据集,set时日志提醒“xx变量已被定义为数值型与字符型”。我想以标准集中的变量格式为标准来定义测试集中的变量。我写了一个宏,但是在测试集运行后变量的类型没有发生改变,为什么?
/******将标准集中的变量类型输出**************/proc contents data=Biaozhun out=summary(keep=name type format);
run;
proc sql noprint;
select count(distinct name) into :amount
from summary;
quit;
proc sql noprint;
select distinct name into :name1-:name%left(&amount)
from summary;
select type into :type1-:type%left(&amount)
from summary;
select format into :format1-:format%left(&amount)
from summary;
quit;
%macro new;
%global fmt;
%let fmt=;
%do i=1 %to &amount;
/*分类型定义变量格式:数值型、日期型、文本型*/
%if &&type&i=1 and &&format&i=%str() %then %do;
%let new=%str(&&name&i=&&name&i*1;);
%end;
%if &&type&i=1 and %sysfunc(compress(&&format&i))=%str(DATE) %then %do;
%let new=%str(&&name&i=input(&&name&i,MMDDYY10.););
%end;
%if &&type&i=2 %then %do;
%let new=%str(&&name&i=put(&&name&i,$60.););
%end;
/*将所有变量的转换格式赋值给全局宏变量fmt*/
%let fmt=&fmt %str(&new);
%end;
%mend;
%new;
data Ceshi;
set Ceshi;
&fmt;/*定义测试集中的变量格式*/
run;