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
|
%MACRO SAS2SQL(table);
*Récupération des noms des variables dans une table;
proc contents data=&table out=content noprint;
run;
*Assignation des noms de variables à des macro-variables;
DATA _null_; SET content end=eof;
format x $1000.;
retain x;
call symput('var'||left(trim(_n_)),NAME);
call symput('nb_var',_n_);
x=CATS(x,',',NAME);
if eof then x=SUBSTR(x,2);
call symput('l_var', x);
run;
%do i =1 %TO &nb_var;
%put Variable &i : &&var&i..;
%end;
%put liste des variables : &l_var;
%put creation du fichier...;
data _null_;
set &table;
file "C:\Documents and Settings\prime-l\Bureau\test.txt";
length ligne $ 1000;
/*Creation de la ligne*/
%do i=1 %to &nb_var;
x=&&var&i..;
y=put(x,$20.);
ligne=CATS(ligne,',',y);
%end;
ligne=CATS("INSERT INTO table (",&l_var ,") VALUES (",SUBSTR(ligne,2),");");
put ligne;
run;
%MEND SAS2SQL; |
Partager