El script utiliza `PROC TEMPLATE` para crear un nuevo tagset. Este tagset, 'counter', está diseñado para interceptar los eventos ODS. Utiliza un diccionario interno para almacenar e incrementar el contador para cada nombre de evento encontrado. Al final del documento (evento `doc finish`), ordena los eventos por orden descendente de frecuencia e imprime un informe de texto simple. El script luego demuestra el uso de este tagset aplicándolo a la salida de `PROC PRINT` en la tabla `sashelp.class`, redirigiendo el informe de conteo a un archivo 'counter.txt'.
Análisis de datos
Type : SASHELP
El script utiliza la tabla `sashelp.class` como ejemplo para generar eventos ODS. Esta tabla no se modifica; solo sirve para activar la ejecución de un procedimiento (`PROC PRINT`) cuyos eventos serán contados por el tagset.
1 Bloque de código
PROC TEMPLATE
Explicación : Este bloque utiliza `PROC TEMPLATE` para definir un nuevo 'tagset' ODS llamado `counter`. Los tagsets permiten controlar finamente la salida generada por SAS. Este está programado para contar las ocurrencias de cada tipo de evento ODS. Utiliza diccionarios (similares a tablas hash) para mantener los conteos. Los eventos clave son `doc` (para la inicialización y finalización), `count` (para incrementar los contadores), `sort` (para ordenar los resultados) y `report` (para mostrar el informe final).
¡Copiado!
/*
Tagset to count the frequency of each event and print a report.
*/
proc template;
define tagset tagsets.counter;
default_event = 'count';
/*
Create an event count dictionary `$events'. Each key in the
dictionary is an event name. The value is the number of times the
event occurred.
At doc start, initialize the event dictionary and the total event
counter. At finish, sort the event names by decreasing occurrence
and print a report.
*/
define event doc;
start:
eval $events[event_name] 1;
eval $total 0;
finish:
trigger sort;
trigger report;
end;
define event count;
do / if $events[event_name];
eval $events[event_name] $events[event_name] + 1;
else;
eval $events[event_name] 1;
done;
eval $total $total+1;
end;
/*
Create an array `$evname' that contains the event names. Sort
`$evname' using the counts in `$events'.
*/
define event sort;
trigger dup;
eval $size $events; /* $size = size of $events */
eval $i $size;
do / while $i > 0;
eval $j 1;
do / while $j < $i;
eval $jplus1 $j+1;
set $evname_j $evname[$j];
set $evname_jplus1 $evname[$jplus1];
do / if $events[$evname_j] < $events[$evname_jplus1];
set $temp $evname[$j];
set $evname[$j] $evname[$jplus1];
set $evname[$jplus1] $temp;
done;
eval $j $j+1;
done;
eval $i $i-1;
done;
end;
define event dup;
iterate $events;
do / while _name_;
set $evname[] _name_;
next $events;
done;
end;
/*
Print the `$events' dictionary in the order specified by the
`$evname' array.
*/
define event report;
put "Number of individual events: " $events nl;
put "Total number of events: " $total nl nl;
put "Count Event name" nl;
iterate $evname;
do / while _value_;
eval $occur $events[_value_];
eval $occur putn($occur, 'F.', 5);
put $occur " " _value_ nl;
next $evname;
done;
end;
end;
run;
1
/*
2
Tagset to count the frequency of each event and print a report.
3
*/
4
5
PROC TEMPLATE;
6
define tagset tagsets.counter;
7
default_event = 'count';
8
9
/*
10
Create an event count dictionary `$events'. Each key in the
11
dictionary is an event name. The value is the number of times the
12
event occurred.
13
14
At doc start, initialize the event dictionary and the total event
15
counter. At finish, sort the event names by decreasing occurrence
16
and print a report.
17
*/
18
define event doc;
19
start:
20
eval $events[event_name] 1;
21
eval $total 0;
22
finish:
23
trigger sort;
24
trigger report;
25
END;
26
27
define event count;
28
DO / IF $events[event_name];
29
eval $events[event_name] $events[event_name] + 1;
30
ELSE;
31
eval $events[event_name] 1;
32
done;
33
eval $total $total+1;
34
END;
35
36
/*
37
Create an array `$evname' that contains the event names. Sort
38
`$evname' using the counts in `$events'.
39
*/
40
define event sort;
41
trigger dup;
42
eval $size $events; /* $size = size of $events */
43
eval $i $size;
44
DO / while $i > 0;
45
eval $j 1;
46
DO / while $j < $i;
47
eval $jplus1 $j+1;
48
SET $evname_j $evname[$j];
49
SET $evname_jplus1 $evname[$jplus1];
50
DO / IF $events[$evname_j] < $events[$evname_jplus1];
51
SET $temp $evname[$j];
52
SET $evname[$j] $evname[$jplus1];
53
SET $evname[$jplus1] $temp;
54
done;
55
eval $j $j+1;
56
done;
57
eval $i $i-1;
58
done;
59
END;
60
61
define event dup;
62
iterate $events;
63
DO / while _name_;
64
SET $evname[] _name_;
65
next $events;
66
done;
67
END;
68
69
/*
70
Print the `$events' dictionary in the order specified by the
71
`$evname' array.
72
*/
73
define event report;
74
put "Number of individual events: " $events nl;
75
put "Total number of events: " $total nl nl;
76
put "Count Event name" nl;
77
iterate $evname;
78
DO / while _value_;
79
eval $occur $events[_value_];
80
eval $occur putn($occur, 'F.', 5);
81
put $occur " " _value_ nl;
82
next $evname;
83
done;
84
END;
85
86
END;
87
88
RUN;
2 Bloque de código
PROC PRINT
Explicación : Este bloque aplica el tagset `tagsets.counter` definido anteriormente. El destino ODS `listing` se cierra, luego el tagset `counter` se activa para escribir en el archivo `counter.txt`. La ejecución de `PROC PRINT` en `sashelp.class` genera eventos que son interceptados y contados por el tagset. Finalmente, el tagset se cierra y el destino `listing` se reactiva.
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.