LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (September 2009, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 3 Sep 2009 12:18:51 +0200
Reply-To:     Daniel Fernández <fdezdan@GMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Daniel Fernández <fdezdan@GMAIL.COM>
Subject:      Re: Include Rho in Output Dataset
Comments: To: Michael <michaelnx@gmail.com>
In-Reply-To:  <20e5d12f0909030236x4776d9e0ofe3d957c2f923917@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

but the best way (if you have SAS version 9 or higher) is to use the ODS OUTPUT method:

Type this code:

ODS TRACE ON;

ODS OUTPUT PEARSONCORR=x.rCorr; *

proc* *corr* data = trans Pearson ; *noprint ;

*if you use option noprint it won´t give you the statistics you want;

var var1-var23 ; *

run*; *QUIT*;

ODS OUTPUT CLOSE;

ODS TRACE OFF;

/* ODS TRACE ON lists in the LOG the different outputs you can reach calling them like this:

ODS OUTPUT the_output_name_you_see_at_LOG= the_dataset_name_you_want ;

as ODS OUTPUT PEARSONCORR= x.rCorr did.

*/

Dani Fernández.

Terrassa Hospital, Barcelona.

El 3 de septiembre de 2009 11:36, Daniel Fernández <fdezdan@gmail.com>escribió:

> Hi Michael, > I think the best you can do is to download this macro from SAS support: > http://support.sas.com/kb/24/addl/fusion24999_1_corrpval.sas.txt > > so then you could make your code like this: > > * > > %macro > *corrpval(version, data=, corr=, out=, byvar=); > > %if > &version ne %then %put CORRPVAL macro Version 1.0; > > %if > %substr(&sysvlong,*1*,*1*)>=*7* %then %do; > > %put CORRPVAL: This macro is obsolete. Use the ODS OUTPUT statement; > > %put %str( to output table PearsonCorr:); > > %put %str( ods output PearsonCorr=<data-set-name>;); > > %end > ; > > * Is there a BY variable? If not, create a dummy BY var ; > > * the macro variable check is an indicator var for ; > > * whether a BY var is not specified; > > data _null_; > > x=( > *2*>length("&byvar &byvar")); > > call symput( > 'check',x); > > if x then call symput( > 'byvar','_byvar_'); > > data &out; > > set &corr; > * subset the corr dataset; > > if &check then &byvar= > *1*; * provide values for dummy BY var; > > if _type_= > 'CORR' then output; > > var1= > ' '; > > var2=var1; > > * create macro variables for the variable names and for; > > * the number of variables in the correlation matrix; > > * only the first BY group is used; > > data _null_; > > set &out end=eof; > > retain _check_; > > if _n_= > *1* then _check_=&byvar; > > if &byvar=_check_ then do; > > if _name_ ne > ' ' then do; > > n+ > *1*; > > call symput( > 'var'||left(n),_name_); > > end; > > end; > > if eof then do; > > call symput( > 'n',n); > > dim=n*(n+ > *1*)/*2*; > > call symput( > 'dim',dim); > > end; > > run; > > * restructure the corr data set; > > data &out; > > set &out; > > cond= > *0*; > > retain _count_ > *0* cond; > > keep &byvar var1 var2 corr ; > > nn=&n*int(_n_/&n)- > *2*; > > if _type_= > 'CORR' then do; > > %do i=*1* %to &n; > > corr=&&var&i; > > var1=_name_; > > var2= > "&&var&i"; > > if var1=var2 then cond= > *1*; > > if cond then output; > > %end; > > end; > > data temp(rename=(_check_=&byvar)); > > retain _check_ > > %do j=*1* %to &dim; > > q&j > > %end; > > ; > > keep _check_ > > %do j=*1* %to &dim; > > q&j > > %end; > > ; > > array nn{&dim} > > %do q0 = *1* %to &dim; > > q&q0 > > %end; > > ; > > set &data end=eof; > > if &check then &byvar= > *1*; > > if _n_= > *1* then do; > > _check_=&byvar; > > do q0= > *1* to &dim; > > nn[q0]= > *0*; > > end; > > end; > > else; > > if _check_=&byvar then do; > > %do q0=*1* %to &n; > > %do q00=&q0 %to &n; > > q000=( &dim - (&n-&q0+ > *1*)*(&n-&q0+*2*)/*2* ) + > > ( &q00 - &q0 + > *1* ); > > nn[q000]=nn[q000]+(&&var&q0> > *.*)*(&&var&q00>*.*); > > %end; > > %end; > > end; > > else do; > > output; > > do q0= > *1* to &dim; > > nn[q0]= > *0*; > > end; > > _check_=&byvar; > > %do q0=*1* %to &n; > > %do q00=&q0 %to &n; > > q000=( &dim - (&n-&q0+ > *1*)*(&n-&q0+*2*)/*2* ) + > > ( &q00 - &q0 + > *1* ); > > nn[q000]=nn[q000]+(&&var&q0> > *.*)*(&&var&q00>*.*); > > %end; > > %end; > > end; > > if eof then do; > > output; > > end; > > run; > > proc transpose data=temp out=temp(drop=_name_); > > by &byvar; > > * compute the p-values after merging the correlation with n values; > > data &out; > > drop _byvar_; > > merge &out temp(rename=(col1=n)); > > if corr= > *.* then do; > > pvalue= > *.*; > > end; > > else if n<= > *2* then do; > > pvalue= > *.*; > > end; > > else if abs(corr)= > *1* then do; > > pvalue= > *0.0*; > > end; > > else do; > > pvalue= > *2**(*1*-probt(abs(corr/sqrt(*1*-(corr*corr)) > > *sqrt(n- > *2*)),n-*2*)); > > end; > > output; > > _byvar_= > *.*; > > run; > * > > %mend > * ; > > > * > > proc > **corr* data = trans outp = x.rCorr pearson noprint ; > > var var1-var23 ;* > > run > * > ; > > %*corrpval*( > data=trans,corr=x.rCorr, out= my_rho_dataset ); > > > > > > Dani Fernández. > > Terrassa Hospital, Barcelona-Spain. > > > > > > 2009/8/31 Michael <michaelnx@gmail.com> > > Hi, >> >> If I do the following, how to include Rho in the output dataset? >> Thanks. Mike. >> >> proc corr data = trans outp = x.rCorr pearson noprint ; >> var var1-var23 ; >> run; >> > >


Back to: Top of message | Previous page | Main SAS-L page