1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| DATA test1 ;
input valeur V1 V2 V3;
datalines;
700 1 0 2
111 0 1 0
;
run;
DATA test2;
input id clef ;
datalines;
72 700
85 700
85 111
;
run;
proc contents data=test1 out=contents;
run;
data _null_;
set contents(where=(upcase(name) ne "VALEUR"));
call symput("Nb_Var", compress(_N_));
call symput(catt("Var_", compress(_N_)), compress(name));
run;
%macro testt();
proc sql;
CREATE table test_0 AS
SELECT t.id,
%do i=1 %to &Nb_var.;
%if &i ne &Nb_var. %then %do;
max(p.&&Var_&i) as &&Var_&i ,
%end;
%else %do;
max(p.&&Var_&i) as &&Var_&i
%end;
%end;
FROM test2 t,
test1 p
WHERE t.clef=p.valeur
GROUP BY t.id
ORDER BY t.id
;
quit;
%mend testt;
%testt(); |
Partager