I would like to group small levels for a list of categorical variable using macro in SAS EG7.15, but it does not work. the same step worked before. I wonder whether others encountered the same issue. Thanks! The &indata. cannot be invoked by SAS even I give a value. Here is error. if I replace the &indata with the true name. no following errors. ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string. ERROR 22-322: Syntax error, expecting one of the following: GROUP, ORDER. Error under group_level_&var. ____________________ 22 ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, (, *, **, +, -, /, ;, <, <=, <>, =, >, ><, >=, AND, EQ, GE, GT, IN, LE, LT, MAX, MIN, NE, NG, NL, NOTIN, OR, [, ^=, {, |, ||, ~=. 160: LINE and COLUMN cannot be determined. error under if then in the data step: ERROR 160-185: No matching IF-THEN clause. Here is the code: %macro grp(indata=, outdata=, threshold=); proc sql; select count(*) into:tot from &indata.; quit; /* Count the number of values in the string */ %let count=%sysfunc(countw(&var_list.)); /* Loop through the total number of values */ %do i = 1 %to &count; %let var=%qscan(&var_list,&i,%str( )); %put &var.; proc sql; create table %unquote(frq_&VAR.) as select "&var." as var format=$30., &var. as %unquote(level_&VAR.) format=$30., count(*) as N , calculated n/&tot. as Percent format=percent7.0 from &indata. group by 1,2 order by 1,2 desc; quit; data %unquote(fgrp_&VAR.2); set %unquote(frq_&VAR.); if n<&threshold. then %unquote(grp_level_&VAR.) = 'Other'; else %unquote(grp_level_&VAR.) = %unquote(level_&VAR.);run; %end; %mend; %grp(indata=lib.abc(where=(TVH2 NE ''))), outdata=lib.out, threshold=800); %grp;
... View more