Bonjour j'essai d'automatiser la création d'un document Excel.

D'habitude j'arrive à mon objectif avec autant de proc tabulate que de variable. Donc c'est facile j'obtiens un seul document Excel avec autant de feuille Excel que de proc tabulate, que de variables.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
48
 
        ods listing close; /*note that this isnt necessary, but prevents duplicate output*/
	ods excel 
	author = 'Ton nom' 
	text =   'BlaBla' 
	file =   "Unweight with missings.xlsx" 
	options  (contents = 'off'            /*creates a worksheet that contains the table of contents*/
			  autofilter = 'none'         /*turns on filtering for specified columns in the worksheet*/
			  embed_footnotes_once = 'on' /*specifies whether embedded footnotes should appear only at the bottom of the worksheet*/
			  embedded_footnotes='on'     /*specifies whether footnotes should appear in the worksheet*/
			  embed_titles_once = 'on'    /*specifies whether embedded titles should appear at the top of the worksheet only once*/
			  embedded_titles='on'        /*specifies whether titles should appear in the worksheet*/
			  flow = 'table'              /*specifies that a designated Worksheet area enables Wrap Text and disables newline character insertion. Excel wraps the text to the column width*/
			  gridlines='off'             /*specifies if grid lines are printed*/
			  hidden_columns = 'none'     /*specifies the columns to hide. You can specify a list of columns to hide or a range of columns to hide*/
			  hidden_rows = 'none'        /*specifies the rows to hide. You can specify a list of rows to hide or a range of rows to hide*/
			  index = 'on'                /*creates a worksheet that contains an index of all worksheets*/
			  protect_worksheet = 'off'   /*protects the worksheet by making it read-only*/
			 sheet_interval='proc'       /*specifies the criteria for when a new worksheet is created*/
			  sheet_name = 'on'
			  start_at = '1,8');
	title    'Sondage (2020)';
 
	%let PH_GROUP = PH_NBALL; /*quelque dizaine ici*/
	%let PH_VARIA = PH_LOS01 PH_SEX01 PH_HEP01; /*(300+ variables ici*/
	%let PH_SHNAM = &PH_VARIA; /*Je test*/ 
 
/*PH_MODUL*/
ods excel options (sheet_name = 'PH_MODUL');
proc tabulate data=SWS1819a;
	weight weightda;
	class PH_MODUL &PH_GROUP / missing;
	var PH_DUMMY;
	table (PH_MODUL ALL = 'total'),	 
		  (&PH_GROUP)*				
		  PH_DUMMY=''*(sum='#' colpctsum='%');		
run;
 
/*PH_GRADE*/
ods excel options (sheet_name = 'PH_GRADE');
proc tabulate data=SWS1819a;
	weight weightda;
	class PH_GRADE &PH_GROUP / missing;
	var PH_DUMMY;
	table (PH_GRADE ALL = 'total'),	 
		  (&PH_GROUP)*				
		  PH_DUMMY=''*(sum='#' colpctsum='%');	
etc etc.
J'essaie d'automatiser pour ne pas avoir a répéter les procédures 300+ fois et pour plusieurs base de données. J'ai toujours les 2 mêmes problèmes.

1. Je n'arrive pas à séparer chacune des procédures dans des feuilles Excel différentes (Sachant que comme c'est une macro variable, il y a simplement une procédure alors).

2. Si j'y arrive comment faire pour que le nom de la feuille excel soit égal au nom de la variable présente dans la macro utilisé pour cette feuille.

Merci infiniment pour votre aide, ça fait plusieurs semaines que je test, mais rien ne semble fonctionner.

J'ai testé plusieurs choses, dont.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
        ods listing close; /*note that this isnt necessary, but prevents duplicate output*/
	ods excel 
	author = 'Ton nom' 
	text =   'BlaBla' 
	file =   "Unweight with missings.xlsx" 
	options  (contents = 'off'            /*creates a worksheet that contains the table of contents*/
			  autofilter = 'none'         /*turns on filtering for specified columns in the worksheet*/
			  embed_footnotes_once = 'on' /*specifies whether embedded footnotes should appear only at the bottom of the worksheet*/
			  embedded_footnotes='on'     /*specifies whether footnotes should appear in the worksheet*/
			  embed_titles_once = 'on'    /*specifies whether embedded titles should appear at the top of the worksheet only once*/
			  embedded_titles='on'        /*specifies whether titles should appear in the worksheet*/
			  flow = 'table'              /*specifies that a designated Worksheet area enables Wrap Text and disables newline character insertion. Excel wraps the text to the column width*/
			  gridlines='off'             /*specifies if grid lines are printed*/
			  hidden_columns = 'none'     /*specifies the columns to hide. You can specify a list of columns to hide or a range of columns to hide*/
			  hidden_rows = 'none'        /*specifies the rows to hide. You can specify a list of rows to hide or a range of rows to hide*/
			  index = 'on'                /*creates a worksheet that contains an index of all worksheets*/
			  protect_worksheet = 'off'   /*protects the worksheet by making it read-only*/
			 /*sheet_interval='bygroups'       specifies the criteria for when a new worksheet is created*/
			  sheet_name = 'on'
			  start_at = '1,8');
	title    'Sondage (2020)';
 
	%let PH_GROUP = PH_NBALL; /*quelque dizaine ici*/
	%let PH_VARIA = PH_LOS01 PH_SEX01 PH_HEP01; /*(300+ variables ici*/
	%let PH_SHNAM = &PH_VARIA; /*Je test*/ 
 
ods excel options (sheet_interval='bygroup'  sheet_name = '#byval1' sheet_label = '');
proc tabulate data=PH2020BTa;
	*weight weightda;
	class &PH_VARIA &PH_GROUP / missing;
	var PH_DUMMY;
	by &PH_VARIA;
	table (&PH_VARIA  ALL = 'total'), 				 
		  (&PH_GROUP)*								
		  PH_DUMMY=''*(sum='#' colpctsum='%');		
run;
 
ods excel close;
ods listing;
PR