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
(dataset3 below).
First I ran this code to get the output in dataset1
ods output PearsonCorr=dataset1;
proc corr data=originaldata;
run;
dataset1
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
data pearsoncorrelations2;
set dataset1;
if Variable = "Y" then output;
run;
dataset2
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.
dataset3
Variable pearsoncoefs PROB
X1 0.10 0.26
X2 -0.14 0.20
Thanks in advance!
data want;
set have;
pearsoncoefs =x1;
PROB =PX1 ;
variable=vname(x1);
output;
pearsoncoefs =x2;
PROB =PX2 ;
variable=vname(x2);
output;
keep Variable pearsoncoefs PROB ;
run;
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.
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).
Try proc transpose as suggested by Reeza
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.