This example illustrates a simple HPDS2 procedure. In this case, the DS2 source statements are executed alongside the database in distributed mode. The DS2 code that is submitted to the grid is contained within the DATA and ENDDATA statements. The following DATA step creates a data set that consists of fictitious daily temperatures that are collected from a number of U.S. airports during a period of one week:
data daily_temps; input city $ mon tue wed thu fri; datalines; lax 88 92 94 97 86 sfo 65 60 75 72 74 nyc 99 95 94 95 90 phl 92 89 91 93 94 atl 95 99 92 98 94 den 85 87 89 72 73 pit 68 70 72 73 77 rdu 98 95 99 95 96 dtt 88 90 90 87 92 anc 51 56 60 64 62 sea 72 78 77 80 79 msy 98 97 99 98 99 mia 95 92 98 94 96 ord 87 85 84 80 79 dfw 95 96 97 95 97 hou 98 99 98 97 92 las 104 105 102 99 101 pdx 78 82 76 74 80 san 80 81 78 82 80 phx 95 98 95 97 100 cle 75 72 76 80 78 ont 78 80 78 81 72 tpa 94 94 92 90 92 bos 80 78 77 75 79 clt 83 80 79 80 81 ; run;
The HPDS2 procedure reads this data set and calculates a daily average temperature in Fahrenheit and Celsius for each airport and then provides a synopsis of the weekly temperature average.
In the following statements, the driver DS2GTF.out in the DATA statement names the input data set, and the SET DS2GTF.in statement names the output data set:
libname applianc &ENGINE server = "&GRIDDATASERVER" user = &USER password = &PASSWORD database = &DATABASE; proc hpds2 data=daily_temps out=applianc.avg_temps; performance host="&GRIDHOST" install="&GRIDINSTALLLOC"; data DS2GTF.out; dcl double avgf avgc; dcl char(5) synopsis; method run(); set DS2GTF.in; avgf = mean(mon, tue, wed, thu, fri); avgc = round((avgf - 32.0) * 5.0/9.0, .1); if avgf >= 95.0 then synopsis = 'Hot'; else if avgf > 80.0 then synopsis = 'Warm'; else if avgf > 60.0 then synopsis = 'Mild'; else synopsis = 'Cold'; end; enddata; run;
The following PRINT procedure displays the table of average temperatures that are produced by the HPDS2 procedure:
proc print data=applianc.avg_temps; title1 'Average Temperatures'; var city synopsis avgf avgc; run;
Figure 6.1 displays the output of the PRINT procedure.
Figure 6.1: Average Temperatures
Average Temperatures |
Obs | city | synopsis | avgf | avgc |
---|---|---|---|---|
1 | lax | Warm | 91.4 | 33.0 |
2 | sfo | Mild | 69.2 | 20.7 |
3 | nyc | Warm | 94.6 | 34.8 |
4 | phl | Warm | 91.8 | 33.2 |
5 | atl | Hot | 95.6 | 35.3 |
6 | den | Warm | 81.2 | 27.3 |
7 | pit | Mild | 72.0 | 22.2 |
8 | rdu | Hot | 96.6 | 35.9 |
9 | dtt | Warm | 89.4 | 31.9 |
10 | anc | Cold | 58.6 | 14.8 |
11 | sea | Mild | 77.2 | 25.1 |
12 | msy | Hot | 98.2 | 36.8 |
13 | mia | Hot | 95.0 | 35.0 |
14 | ord | Warm | 83.0 | 28.3 |
15 | dfw | Hot | 96.0 | 35.6 |
16 | hou | Hot | 96.8 | 36.0 |
17 | las | Hot | 102.2 | 39.0 |
18 | pdx | Mild | 78.0 | 25.6 |
19 | san | Warm | 80.2 | 26.8 |
20 | phx | Hot | 97.0 | 36.1 |
21 | cle | Mild | 76.2 | 24.6 |
22 | ont | Mild | 77.8 | 25.4 |
23 | tpa | Warm | 92.4 | 33.6 |
24 | bos | Mild | 77.8 | 25.4 |
25 | clt | Warm | 80.6 | 27.0 |