01-10-2018 03:01 PM
I need the pearson correlation coefficents and respective probabilities for the
independent variables of a regression in a nice table (like dataset3 below).
First for one regression, then I'll be adding more regressions to the dataset
First I ran this code to get the output in dataset1
ods output PearsonCorr=dataset1;
proc corr data=originaldata;
Variable Label x1 x2 y PX1 PX2 PY
X1 1.00 0.25 0.10 _ 0.23 0.26
X2 0.25 1.00 -0.14 0.23 _ 0.20
Y Y 0.10 -0.14 1.00 0.26 0.20 _
It has more columns/values than I need, so
modified above data with below code to get dataset2
if Variable = "Y" then output;
Variable Label X1 X2 Y PX PX2 PY
Y Y 0.10 - 0.14 1 0.26 0.20 _
But now I need
the data in the following format, but how do i do that? I also
don't need the Label and PY columns.
Variable pearsoncoefs PROB
X1 0.10 0.26
X2 -0.14 0.20
Thanks in advance!
01-10-2018 03:06 PM - edited 01-10-2018 03:08 PM
PROB =PX1 ;
PROB =PX2 ;
keep Variable pearsoncoefs PROB ;
01-10-2018 03:21 PM
Try PROC TRANSPOSE if you need a dynamic option. If you need just for your example data, then @novinosrin code is suitable.
You would like need a double transpose, once to a wide format and once to the desired format.
01-10-2018 03:58 PM
Thanks both for your quick responses. It works now but as you can imagine I don't want to
have to manually type in the name of the variables as for some regressions there might be more than 2 variables. Is there a way to do that? I was looking into the syntax for the "%do loop in SAS but it didn't look like it works for this case (variable names).