I am running PROC CORR to determine Pearson, Spearman, and Kendall correlations on 101 variables against a single variable. For example, for age, gender, race, etc. I want to see the correlation to whether the person uses the internet. The procedure is running fine and giving me the data that I want, but because I am comparing against 101 variables, the results are very wide and run off the page.
Is there a way to display the same results vertically, so that I have only three columns (Pearson, Spearman, and Kendall) and 101 rows?
SAS Univeristy Edition, release 3.5, build 3 Feb 2016.
SURE. proc corr data=sashelp.class noprint outp=pearson outs=spearman outk=kendall; var weight height; with age; run; data temp; set pearson spearman kendall indsname=indsname; dsn=scan(indsname,-1,'.'); if _type_='CORR'; run; proc transpose data=temp out=want; id dsn; var _numeric_; run; proc datasets library=work nolist nodetails; save want; quit;
Put that single variable in WITH statement, other 101 variables in VAR statement. OR Do you want IML code ? proc corr data=sashelp.class noprint outp=pearson outs=spearman outk=kendall; var weight height; with age; run; data temp; set pearson spearman kendall indsname=indsname; dsn=scan(indsname,-1,'.'); if _type_='CORR'; run; proc transpose data=temp out=want; id dsn; var _numeric_; run;
Thank you, that works perfectly.
For bonus points, is there a way that I can automatically drop the four temporary tables in the script, so that only the WANT table is left at the end?
SURE. proc corr data=sashelp.class noprint outp=pearson outs=spearman outk=kendall; var weight height; with age; run; data temp; set pearson spearman kendall indsname=indsname; dsn=scan(indsname,-1,'.'); if _type_='CORR'; run; proc transpose data=temp out=want; id dsn; var _numeric_; run; proc datasets library=work nolist nodetails; save want; quit;
Excellent. Thanks very much for your help.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.