Sas 无法将宏变量与数据集变量匹配
数据集中的字符变量从不与宏变量匹配。%IF循环永远不会实现。好心的建议 我尝试按月份匹配,并相应地尝试创建数组,并仅对特定月份进行计数。无法工作,因为month宏变量从未与具有month的数据集变量匹配Sas 无法将宏变量与数据集变量匹配,sas,sas-macro,Sas,Sas Macro,数据集中的字符变量从不与宏变量匹配。%IF循环永远不会实现。好心的建议 我尝试按月份匹配,并相应地尝试创建数组,并仅对特定月份进行计数。无法工作,因为month宏变量从未与具有month的数据集变量匹配 /*create dummy data*/ data datefile; input tran_date date9. cnt 3.; datalines; 13feb2015 5 10feb2015 4 11feb2015 3 05feb2015 8 08feb2015
/*create dummy data*/
data datefile;
input tran_date date9. cnt 3.;
datalines;
13feb2015 5
10feb2015 4
11feb2015 3
05feb2015 8
08feb2015 5
01jan2015 1
20dec2014 1
31jan2015 2
23dec2014 2
12jan2015 1
;
/*calculate month*/
data datefile11;
set datefile;
tran_mon=year(tran_date)*100+month(tran_date);
run;
/*select distinct month*/
proc sql;
create table datefile12 as select distinct(tran_mon)
from datefile11 order by tran_mon;
quit;
/*convert month from numeric to character*/
data datefile11(drop=tran_mon);
informat tran_mon2 $6.;
set datefile11;
tran_mon2=tran_mon;
run;
/*create macro variables through datastep*/
data datefile13;
set datefile12;
monum = cat('mnth',_N_);
run;
data _null_;
set datefile13;
call symput(monum,trim(left(tran_mon)));
run;
/*use array to make separate column for each month and
put split count for each month to each colunms*/
%macro c;
proc sql noprint;
select count(1) into :nrow from datefile13;
quit;
%let nrow = &nrow;
data datefile14;
set datefile11;
array mon{*} mon_1 - mon_&nrow;
%do i=1 %to &nrow;
%if tran_mon2 = &&mnth&i %then %do; %put tran_mon2;
mon_&i = cnt; %end;
%else %do; mon_&i = 0 ; %end;
%end;
run;
%mend c;
%c
您的宏
%if%then%do
检查在数据步骤仍在编译时执行-当数据步骤开始执行时,不再有机会使用这样的宏逻辑
尝试另一种方法——使用if编写循环,然后改为使用data-step逻辑