BookmarkSubscribeRSS Feed
Berenice25
SAS Employee
/************************************/
/************************************/
/*									*/
/*   SAS - Customer Success Latam 	*/
/*									*/
/************************************/
/************************************/


/************************************/
/************************************/
/*									*/
/*      Webinar: SAS y Excel		*/
/*            23Jun2022             */
/*									*/
/************************************/
/************************************/


/************************************/
/* Expositor: Daniel Vazquez Vargas */
/************************************/


/****************************/
/*	Uso de "ODS ods html"	*/
/****************************/


/****************************************/
/* 	  Ejemplos de diferentes estilos 	*/
/*	  usando Proc Report 				*/
/****************************************/




/*-------------------*/
/* inicio del código */
/*-------------------*/
 

/* 5 ejemplos: Estilos con Proc Report */
/* Uso de formatos de celdas (o casillas) combinando Proc Report + ods html file */

/* Antes de comenzar con los ejemplos, vamos a crear un formato y un dataset */

/* En primer lugar creo un formato para manejar colores */
proc format;
	value colorme 1='white' 2='purple'; /*¡sí, colores! Pueden elegir el que deseen*/
run;

/* En segundo lugar el dataset para los ejemplos (si miran con atención van a 
poder comprobar que es un dataset un poco extraño) */
data cuadricula;
	input fila $ col $ valor;
	cards;
1 a 1
1 b 2
1 c 1
1 d 2
2 a 2
2 b 1
2 c 2
2 d 1
3 a 1
3 b 2
3 c 1
3 d 2
4 a 2
4 b 1
4 c 2
4 d 1
;
run;

title; 
footnote;

ods listing; 


/* Ahora sí los reportes */

/* Ejemplo 1: estilos en general */

title1 justify=center font='Arial' height=10pt color=black bold bcolor=lightgrey "Usando 
un estilo en general";

ods html file='g:/temp/control_background01.xls';  /*desde ya que probamos con un 
archivo de extensión xlsx, pero no funciona; Excel no lo reconoce; ¡y sabemos el porqué!*/

proc report nowd data=cuadricula /*sin usar estilos en 'define'*/
	style=[cellwidth=.1in rules=group frame=void]
		style(column header)=[background=yellow foreground=black];
	col fila col , valor;
	define fila / group ' ';
	define valor / ' ';
	define col / across ' ';
run;

ods html close;
title;
footnote;

ods listing;


/* Ejemplo 2: estilos predefinidos en filas y columnas en 'define' */

title1 justify=center font='Arial' height=10pt color=black bold bcolor=lightgrey "Usando estilos 
predefinidos en filas y columnas en 'define'";

ods html file='g:/temp/control_background02.xls';

proc report nowd data=cuadricula  /*usando estilos predefinidos en filas y columnas en 'define'*/
	style=[cellwidth=.1in rules=group frame=void]
		style(column header)=[background=yellow foreground=red];
	col fila col , valor;
	define fila / group ' '
		style(column header)=[foreground=black background=green];
	define valor / ' ';
	define col / across
		style(header)=[foreground=black background=green] ' ';
run;

ods html close;
title;
footnote;

ods listing;


/* Ejemplo 3: formato 'colorme' para forma y fondo en 'define' */

title1 justify=center font='Arial' height=10pt color=black bold bcolor=lightgrey "Usando el formato 
'colorme' para forma y fondo en 'define'";

ods html file='g:/temp/control_background03.xls';

proc report nowd data=cuadricula  /*usando el formato 'colorme' para forma y fondo en 'define'*/
	style=[cellwidth=.1in rules=group frame=void]
		style(column header)=[background=yellow foreground=red];
	col fila col , valor;
	define fila / group ' '
		style(column header)=[foreground=black background=green];
	define valor / ' '
		style(column)=[background=colorme. foreground=colorme.] ' ';
	define col / across
		style(header)=[foreground=black background=green] ' ';
run;
ods html close;

title;
footnote;

ods listing;


/* Ejemplo 4: formato 'colorme' solamente para el fondo */

title1 justify=center font='Arial' height=10pt color=black bold bcolor=lightgrey "Usando el formato 
'colorme' solamente para el fondo en 'define'";

ods html file='g:/temp/control_background04.xls';

proc report nowd data=cuadricula /*usando el formato 'colorme' solamente para el fondo en 'define'*/
	style=[cellwidth=.1in rules=group frame=void]
		style(column header)=[background=yellow foreground=red];
	col fila col , valor;
	define fila / group ' '
		style(column header)=[foreground=black background=green];
	define valor / ' '
		style(column)=[background=colorme. foreground=black] ' ';
	define col / across
		style(header)=[foreground=black background=green] ' ';
run;

ods html close;
title;
footnote;

ods listing;



/* Para finalizar, cambiamos de dataset. Vamos a utilizar una tabla de las tradicionales: sashelp.class */
/* Verán que el resultado les puede parecer confuso. Pero era preferible que lo vieran con una tabla muy elemental
para poder replicarlo en tablas de datos más grandes */


/* Ejemplo 5: Utilizamos diferentes colores cuando hacemos sumarizaciones*/

title1 justify=center font='Arial' height=10pt color=black bold bcolor=lightgrey "Colores de acuerdo 
al orden jerárquico";

ods html file='g:/temp/control_background05.xls';

proc report nowd data=sashelp.class (obs=2)
	style(column header summary)=[font_size=1 background=white];
	define name / order;
	define age / order;
	break after name / summarize style=[background=green font_weight=bold]; 
	break after age / summarize style=[background=yellow font_style=roman];
	rbreak after / summarize style=[background=orange];
	rbreak before / summarize;
run;

ods html close;

title;
footnote;

ods listing;



/*--------------------*/
/* 	fin del código	  */
/*--------------------*/

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Discussion stats
  • 0 replies
  • 971 views
  • 3 likes
  • 1 in conversation