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
| DATA toto;
input age;
cards;
48
78
96
69
;
run;
%macro VarExiste(TABLE,colonne,variable);
proc sql noprint;
SELECT count(*) INTO :nb FROM &TABLE;
SELECT &colonne INTO :val separated BY '|' FROM &TABLE;
quit;
%do i=1 %TO &nb;
%let var&i=%scan(&val,&i,'|');
%IF &variable=&&var&i %then %do;
%let existe=1;
%end;
%else %do;
%let existe=0;
%end;
%end;
%let resultat=&existe.;
%put resultat=&resultat.;
%IF &resultat=1 %then %do;
proc sql;
create table tr_5 as
SELECT * FROM toto;
quit;
%end;
%mend;
%VarExiste(toto,age,10);
%VarExiste(toto,age,69); |
Partager