Help using Base SAS procedures

Concatenating SAS datasets horizontally

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 82
Accepted Solution

Concatenating SAS datasets horizontally

I'm running seven regressions on multiple outcomes using the same model specification.  I want to create a Word file that contains all of the coefficients and p values in a single table, like one that you might present in a journal article.

Let's say I'm running a regression using PROC SURVEYREG (note that the variable Probt is the p value):

proc surveyreg data = dataset;

weight perwt;

strata varstr;

cluster varpsu;

class sex region;

model spending = age sex region /solution;

ods output ParameterEstimate = coefficients (keep = Parameter Estimate Probt);

run;

The dataset coefficients might look something like this:

Parameter        Estimate       Probt

AGE                0.396            0.002

SEX                 0.002            0.953  

REGION           0.125            0.593

Let's say I run a second regression using identical code, except that I use a different outcome variable (say, HEALTH).  I then save the ParameterEstimate table to a dataset coefficients2. 

Parameter        Estimate        Probt

AGE                0.132            0.321

SEX                 0.352            0.835  

REGION           0.653            0.001

What I want to make is a single table that looks like this:

                      SPENDING                           HEALTH

Parameter        Estimate       Probt               Estimate        Probt

AGE                0.396            0.002               0.132             0.321

SEX                 0.002            0.953               0.352             0.835

REGION           0.125            0.593               0.653             0.001

It's easy to concatenate SAS datasets vertically (by stacking them on top of each other) but I want to figure out how to do this "horizontally."  I don't know PROC SQL and don't know if there's a good way to do this without using this PROC.

Thanks.


Accepted Solutions
Solution
‎03-09-2012 12:26 PM
Super Contributor
Posts: 1,636

Re: Concatenating SAS datasets horizontally

how about:

data have1;

input Parameter $ :       s_Estimate      : s_Probt;

cards;

AGE                0.396            0.002

SEX                 0.002            0.953  

REGION           0.125            0.593

;

run;

data have2;

input Parameter $ :       h_Estimate      : h_Probt;

cards;

AGE                0.132            0.321

SEX                 0.352            0.835  

REGION           0.653            0.001

run;

data want;

merge have1 have2;

run;

proc print;run;

                 Obs    Parameter    s_Estimate    s_Probt    h_Estimate    h_Probt

                 1      AGE            0.396       0.002        0.132       0.321

                 2      SEX            0.002       0.953        0.352       0.835

                 3      REGION         0.125       0.593        0.653       0.001

Linlin

View solution in original post


All Replies
Occasional Contributor
Posts: 18

Re: Concatenating SAS datasets horizontally

Try This ,

PROC SQL;

create table results as

select a.parameter , 

          a.Estimate as Spending_estimate ,

          a.probt as Spending_probt ,

          b.estimate as Health__Estimate ,

          b.probt as Health_probt

from Table1 as a inner join  table2 as b

on a.parameter = b.parameter;

quit;

Here if you want to include non-common records also then use Full outer join with COALESCE(a.parameter,b.parameter).

Solution
‎03-09-2012 12:26 PM
Super Contributor
Posts: 1,636

Re: Concatenating SAS datasets horizontally

how about:

data have1;

input Parameter $ :       s_Estimate      : s_Probt;

cards;

AGE                0.396            0.002

SEX                 0.002            0.953  

REGION           0.125            0.593

;

run;

data have2;

input Parameter $ :       h_Estimate      : h_Probt;

cards;

AGE                0.132            0.321

SEX                 0.352            0.835  

REGION           0.653            0.001

run;

data want;

merge have1 have2;

run;

proc print;run;

                 Obs    Parameter    s_Estimate    s_Probt    h_Estimate    h_Probt

                 1      AGE            0.396       0.002        0.132       0.321

                 2      SEX            0.002       0.953        0.352       0.835

                 3      REGION         0.125       0.593        0.653       0.001

Linlin

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 6822 views
  • 4 likes
  • 3 in conversation