%macro trans(case1=,index1=);
%local n1 n2 index1 case1 VarName;
%let n1=%sysfunc(countw(&case1,%str(|)));
%let n2=%sysfunc(countw(&Index1,%str(|)));
proc sort data=orig_Table out=out_Table;
by Case Variable;
where 1=1
%do i=1 %to &n1;
%if &i eq 1 %then %do;
AND Case in (
"%qscan(&Case1,&i,%str(|))"
%end;
%else %do;
,"%qscan(&Case1,&i,%str(|))"
%end;
%if &i eq &n1 %then %do;
)
%end;
%end;
%do i=1 %to &n2;
%if &i eq 1 %then %do;
AND Variable in (
"%qscan(&Index1,&i,%str(|))"
%end;
%else %do;
,"%qscan(&Index1,&i,%str(|))"
%end;
%if &i eq &n2 %then %do;
)
%end;
%end;
;
run;
%if &n2 eq 0 %then %do;
proc sql noprint;
select distinct strip(Variable) into :Index1 separated by '|'
from out_Table
where Variable^=''
;
quit;
%let n2=%sysfunc(countw(&Index1,%str(|)));
%end;
data out_Table;
set out_Table;
by Case Variable;
array array_Y Y112-Y114;
%do i=1 %to &n2;
%let VarName=%qscan(&Index1,&i,%str(|));
array %unquote(A_&Varname &Varname.1-&Varname.3);
retain %unquote(&VarName.1-&VarName.3);
%end;
if first.Case then do;
%do i=1 %to &n2;
%let VarName=%qscan(&Index1,&i,%str(|));
call missing(of %unquote(A_&Varname.{*}));
%end;
end;
%do i=1 %to &n2;
%let VarName=%qscan(&Index1,&i,%str(|));
%if &i eq 1 %then %do;
select;
%end;
when(Variable="&VarName") do over array_Y;
%unquote(A_&VarName)=array_Y;
end;
%if &i eq &n2 %then %do;
otherwise do;
end;
end;
%end;
%end;
if last.Case;
drop Variable Y112-Y114;
run;
%mend;
%trans(case1=Basic,index1=Temperature|Speed);
/*%trans(case1=Basic|Serious,index1=Temperature|Speed);*/
/*%trans(case1=Basic);*/
/*%trans(case1=Basic,index1=Temperature);*/
/*%trans(case1=Basic);*/
/*%trans(index1=Temperature);*/
/*%trans();*/
... View more