The scope of this example is to show how to use a statistics obtained by reading a data set to modify the values of another. In particular it will be evaluated the mean and the standard deviation of a series of values and, in a next step, these will be used to standardize the original values.
In order to run this example just paste the following statements in the Command area and press the execute button. To view the resulting data set just go in the PATH tab and refer to the one named Standardized.
dataset out=Casualds; newvar v=num; for (int i=0; i<100; i++) { v=Math.random(); output; }; run; dataset dict=Casualds out=_NULL_; EVALSTAT test; ADDVAL(TEST, v); if (LAST_DICT) { SHAREDOBJECTS.put("mean", GETMEAN(TEST)); SHAREDOBJECTS.put("std", GETSTD(TEST)); }; run; dataset dict=Casualds out=Standardized; newvar v_stand=num; exebefore; double mean=(Double)SHAREDOBJECTS.get("mean"); double std=(Double)SHAREDOBJECTS.get("std"); endexebefore; v_stand=(v-mean)/std; run; |