/*The p-value is determined by figuring where the real */ /*results lie within the distribution of the permuted */ /*results within a probe. The permuted and real results */ /*of the test are ranked, and then the rank is used to */ /*calculate the p-value. The original results have a */ /*value of -1 in the permute variable. The p-values of */ /*the real results are merged into a single data set */ /*named using the name for the original data set followed */ /*by "_pvalues". */ /* */ /*To invoke this suite of macros call on the macro */ /*real_pvalues and insert the following positional */ /*parameters: the name of the data set, the name of the */ /*unique identifier for the probes, the number of */ /*permutations, the name of the variable where the */ /*permutation number is stored, the name of the test that */ /*the p-value is to be computed on, the name of the */ /*column that names the effects, and the list of up to */ /*five effects, interactions, or contrasts, separated by */ /*commas. */ /* */ /*Note: It is assumed that interactions are renamed so */ /*that there is no asterisk(s) within the name. Also, */ /*effects1-effects5 are case sensitive. */ %macro find_pvalue(infile,probe_id,effect,num_perms,permute,test,effect_col); *subsetting the appropriate effect and formatting the test value column; data one_effect; set &infile; where &effect_col="&effect" and &test ne .; &test.1=&test*1; run; *checking for ties in the test values; proc freq data=one_effect noprint; by &probe_id; tables &test.1/out=&test._count; run; *sorting the data by probe and test values; proc sort data=one_effect; by &probe_id &test.1; proc sort data=fvalue_count; by &probe_id &test.1; run; *merging the counts and test values; data one_effect_count; merge one_effect &test._count; by &probe_id &test.1; keep &probe_id count &test.1 &permute; run; *ranking the fvalues within a probe; proc rank data=one_effect_count out=rank_&effect; by &probe_id; var &test.1; ranks rank_&test; run; *subsetting and calculating the p-values for the real results. if one of the real results has a tie with a permuted result, then the real result is given the highest rank; data rank_tie_&effect; set rank_&effect; where &permute=-1; if count>1 then rank_tie=rank_&test+0.5; else rank_tie=rank_&test; sig_&effect=1-((rank_tie-1)/&num_perms); keep sig_&effect &probe_id &permute; run; %mend find_pvalue; %macro real_pvalues(infile,probe_id,num_perms,permute,test,effect_col,effect1,effect2,effect3,effect4,effect5); *sorting by probe; proc sort data=&infile; by &probe_id; run; *calling on the find_pvalue macro for each of the effects; %find_pvalue(&infile,&probe_id,&effect1,&num_perms,&permute,&test,&effect_col); %find_pvalue(&infile,&probe_id,&effect2,&num_perms,&permute,&test,&effect_col); %find_pvalue(&infile,&probe_id,&effect3,&num_perms,&permute,&test,&effect_col); %find_pvalue(&infile,&probe_id,&effect4,&num_perms,&permute,&test,&effect_col); %find_pvalue(&infile,&probe_id,&effect5,&num_perms,&permute,&test,&effect_col); *merging the real p-value results from each of the effects; data &infile._pvalues; merge rank_tie_&effect1 rank_tie_&effect2 rank_tie_&effect3 rank_tie_&effect4 rank_tie_&effect5; by &probe_id; drop sig_; run; %mend real_pvalues;