Programming the statistical procedures from SAS

Proc reg by group output with p value

Reply
Occasional Contributor
Posts: 16

Proc reg by group output with p value

[ Edited ]

 

proc reg data=aaa noprint outest=bbb;
by year;
model y=x1 x2;
proc print data=bbb; run;

 

This gives me estimated coefficient per year, but I want to have another column with p-value next to the coefficient. Is there any way that I can do that? I used table out, but it adds rows, not columns that just complicates my reading through the output. 

 

Thank you for your reply in advance. 

SAS Moderator
Posts: 61

Re: Proc reg by group output with p value [how to improve your question]

Hello @kelSAS,


Your question requires more details before experts can help. Can you revise your question to include more information? 

 

Review this checklist:

  • Specify a meaningful subject line for your topic.  Avoid generic subjects like "need help," "SAS query," or "urgent."
  • When appropriate, provide sample data in text or DATA step format.  See this article for one method you can use.
  • If you're encountering an error in SAS, include the SAS log or a screenshot of the error condition. Use the Photos button to include the image in your message.
    use_buttons.png
  • It also helps to include an example (table or picture) of the result that you're trying to achieve.

To edit your original message, select the "blue gear" icon at the top of the message and select Edit Message.  From there you can adjust the title and add more details to the body of the message.  Or, simply reply to this message with any additional information you can supply.

 

edit_post.png

SAS experts are eager to help -- help them by providing as much detail as you can.

 

This prewritten response was triggered for you by fellow SAS Support Communities member @ballardw

.
Super User
Posts: 13,508

Re: Proc reg by group output with p value

You can use proc transpose to change rows to columns from the TABLEOUT option.

 

Or use ods output to send the displayed parameter estimates table to a data set.

proc reg data=sashelp.baseball;
   id name team league;
   model logSalary = nhits nruns nrbi nbb yrmajor crhits;
   ods output parameterestimates=work.parms;
run;

Send the variable, degrees of freedom, parameter esitmat, std err of the parameter, t value and the probT (p-vale) to the data set WORK.PARMS.

 

 

This is a very useful approach to know as some table of information are not at all accessible with any of the OUT= options and many of the newer procedures rely on this to get displayed table values into data sets. The online documentation for procedures in the details section will usually have a section of "ODS Table Names" you can reference or use the ODS TRACE ON/OFF; before after a procedure to see the names of tables generated.

Occasional Contributor
Posts: 16

Re: Proc reg by group output with p value

[ Edited ]

Thank you so much. I used 

 

 

 

proc reg data=aaa;
by year;
model y=x1 x2;
ods output parameterestimates=bbb;

 

 

then, to only have coefficients and p-value, I used below transpose and merge.

 

 

proc transpose data=bbb out=ccc prefix=x;
by fyear;
id variable;
var estimate;

proc transpose data=bbb out=ddd prefix=p;
by fyear;
id variable;
var probt;
run;

data ddd;
merge bbb(drop=_name_) ccc(drop=_name_);
by year;run;

proc print data=ddd;run;

 

 

This is so inefficient, but I got what I needed, so that's good, I guess.

Thank you so much for your help.

Super User
Posts: 13,508

Re: Proc reg by group output with p value


@kelSAS wrote:

Thank you so much. I used 

 

 

 

proc reg data=aaa;
by year;
model y=x1 x2;
ods output parameterestimates=bbb;

 

 

then, to only have coefficients and p-value, I used below transpose and merge.

 

 

proc transpose data=bbb out=ccc prefix=x;
by fyear;
id variable;
var estimate;

proc transpose data=bbb out=ddd prefix=p;
by fyear;
id variable;
var probt;
run;

data ddd;
merge bbb(drop=_name_) ccc(drop=_name_);
by year;run;

proc print data=ddd;run;

 

 

This is so inefficient, but I got what I needed, so that's good, I guess.

Thank you so much for your help.


With no data I have no idea what you are building for your desired data set. I'm also confused by the use of YEAR in part of the code and FYEAR in others.

 

Proc report or proc tabulate likely can create a usable table with the BBB set directly but again without data I can't tell exactly. Something like:

proc report data=bbb;
   column fyear variable,(estimate probt);
   define fyear /group;
   define variable /across;
   define estimate/analysis;
   define probt/analysis;
run;

 

 

You might be interested to know that you can use data set options with the ODS output to only keep the variables you want such as

Ask a Question
Discussion stats
  • 4 replies
  • 192 views
  • 2 likes
  • 3 in conversation