Frequencies and statistics within a data step
This example read a data set and, inside the data step, uses two ADaMSoft methods that will be used to evaluate the mean and the different values of two variables, one numerical and the other alphanumerical.
In order to run this example just paste the following statements in the Command area and press the execute button. To view the content of the resulting data sets (one for the mean the other with the frequencies) just go in the PATH tab and refer to the ones named Mean and Freqs.
This example read a data set and, inside the data step, uses two ADaMSoft methods that will be used to evaluate the mean and the different values of two variables, one numerical and the other alphanumerical.
In order to run this example just paste the following statements in the Command area and press the execute button. To view the content of the resulting data sets (one for the mean the other with the frequencies) just go in the PATH tab and refer to the ones named Mean and Freqs.
dataset out=Casualds; newvar v1-v5=num; newvar v6-v19=text; for (int i=0; i<100; i++) { v1=Math.random(); v2=Math.random(); v3=Math.random(); v4=Math.random(); v5=Math.random(); v6="V1 less than .5"; v7="V2 less than .5"; v8="V3 less than .5"; v9="V4 less than .5"; v10="V5 less than .5"; if (v1>.5) v6="V1 greater than .5"; if (v2>.5) v7="V2 greater than .5"; if (v3>.5) v8="V3 greater than .5"; if (v4>.5) v9="V4 greater than .5"; if (v5>.5) v10="V5 greater than .5"; output; }; run; dataset dict=Casualds out=mean; newvar mean=num; EVALSTAT test; ADDVAL(TEST, v1); if (LAST_DICT) { mean=GETMEAN(TEST); output; }; keep mean; run; dataset dict=Casualds out=freqs; newvar values=text; newvar freq=num; FREQCOUNTER f; ADDFREQ(F, v6); if (LAST_DICT) { for (int i=0; i values=GETNAMEFOR(F, i); freq=GETFREQAT(F, i); output; } }; keep values freq; run; |