Los datos provienen del conjunto de datos SASHELP.AIR, un ejemplo de datos integrado en SAS.
1 Bloque de código
DATA STEP
Explicación : Este bloque DATA _NULL_ genera dinámicamente un procedimiento PROC FORMAT. Crea un formato llamado `pct_` que mapea valores numéricos (representando un porcentaje de 0 a 1) a códigos de color hexadecimales. Los colores varían progresivamente del azul (frío, bajo porcentaje) al rojo (cálido, alto porcentaje). Los valores fuera del rango definido reciben un color gris por defecto.
¡Copiado!
* Create a format to display colors ranging from Blue (cold) to Red (hot) ;
data _null_ ;
call execute('proc format fmtlib ; value pct_') ;
max=1;
maxloop=255 ;
do i=1 to maxloop ;
color='cx'||put(i/maxloop*255,hex2.)||'00'||put((maxloop-i)/maxloop*255,hex2.) ;
from=((i-1)/maxloop)*max ;
to=(i/maxloop)*max ;
call execute(put(from,best.)||'-'||put(to,best.)||'='||quote(color)) ;
end ;
call execute('.="light gray" other="cxd0d0d0" ; run ;') ;
run ;
1
* Create a format to display colors ranging from Blue (cold) to Red (hot) ;
call execute('.="light gray" other="cxd0d0d0" ; run ;') ;
13
RUN ;
2 Bloque de código
PROC SQL
¡Copiado!
* get the maximum value of air ;
proc sql ;
select max(air),min(air) into :max,:min from sashelp.air ;
%let range=%sysevalf(&max-&min) ;
1
* get the maximum value of air ;
2
PROC SQL ;
3
select max(air),min(air) into :max,:min from sashelp.air ;
4
%let range=%sysevalf(&max-&min) ;
3 Bloque de código
DATA STEP Data
¡Copiado!
* express values of air as a percentage of the maximum ;
data air ;
set sashelp.air ;
year=year(date) ;
month=month(date) ;
* percentage is the level above the minimum ;
pct=(air-&min)/&range ;
run ;
1
* express values of air as a percentage of the maximum ;
2
DATA air ;
3
SET sashelp.air ;
4
year=year(date) ;
5
month=month(date) ;
6
* percentage is the level above the minimum ;
7
pct=(air-&min)/&range ;
8
RUN ;
4 Bloque de código
PROC TABULATE
¡Copiado!
* tabulate the results indicating maximum as red, minimum as blue ;
ods html file='test.html' ;
title 'Air Quality over the years' ;
footnote 'Blue (cold) is best, Red (hot) is worst' ;
proc tabulate data=air style={background=pct_.} ;
class year month ;
var pct ;
label pct='Air Quality Percent of worst month' ;
table sum=''*pct*f=percent.,year='Year',month='Month of Year' ;
run ;
ods html close ;
1
* tabulate the results indicating maximum as red, minimum as blue ;
2
ods html file='test.html' ;
3
title 'Air Quality over the years' ;
4
footnote 'Blue (cold) is best, Red (hot) is worst' ;
5
PROC TABULATEDATA=air style={background=pct_.} ;
6
class year month ;
7
var pct ;
8
label pct='Air Quality Percent of worst month' ;
9
TABLE sum=''*pct*f=percent.,year='Year',month='Month of Year' ;
10
RUN ;
11
ods html close ;
Este material se proporciona "tal cual" por We Are Cas. No hay garantías, expresas o implícitas, en cuanto a la comerciabilidad o idoneidad para un propósito particular con respecto a los materiales o el código contenidos en este documento. We Are Cas no es responsable de los errores en este material tal como existe ahora o existirá, ni We Are Cas proporciona soporte técnico para el mismo.
SAS y todos los demás nombres de productos o servicios de SAS Institute Inc. son marcas registradas o marcas comerciales de SAS Institute Inc. en los EE. UU. y otros países. ® indica registro en los EE. UU. WeAreCAS es un sitio comunitario independiente y no está afiliado a SAS Institute Inc.
Este sitio utiliza cookies técnicas y analíticas para mejorar su experiencia.
Saber más.