I am not sure if what I am trying to do is even possible, so I thought I would check with more experienced SAS users.
I want to run Proc GLM many, many times using the "by" statement and then have output parameters for each run go into a single a file. The output parameters are something like a, b, # points, and R2.
Is this possible?
Thank you!!
You can output the results from proc glm in a (several) table(s).
To retrieve the output of proc glm, one can use the ods trace statement to track the object(s) output of proc glm. For more information, please consider reading the ODS TRACE Statement documentation.
proc glm output 6 objects: NObs, OverallANOVA, FitStatistics, ModelANOVA, ModelANOVA and ParameterEstimates.
29 ods trace on;
30 proc glm data=sashelp.cars;
31 model length = mpg_city ;
32 quit;
Output Added:
-------------
Name: NObs
Label: Number of Observations
Template: STAT.GLM.NObsNotitle
Path: GLM.Data.NObs
-------------
Output Added:
-------------
Name: OverallANOVA
Label: Overall ANOVA
Template: stat.GLM.OverallANOVA
Path: GLM.ANOVA.Length.OverallANOVA
-------------
Output Added:
-------------
Name: FitStatistics
Label: Fit Statistics
Template: stat.GLM.FitStatistics
Path: GLM.ANOVA.Length.FitStatistics
-------------
Output Added:
-------------
Name: ModelANOVA
Label: Type I Model ANOVA
Template: stat.GLM.Tests
Path: GLM.ANOVA.Length.ModelANOVA
-------------
Output Added:
-------------
Name: ModelANOVA
Label: Type III Model ANOVA
Template: stat.GLM.Tests
Path: GLM.ANOVA.Length.ModelANOVA
-------------
Output Added:
-------------
Name: ParameterEstimates
Label: Solution
Template: stat.GLM.Estimates
Path: GLM.ANOVA.Length.ParameterEstimates
-------------
I induce that by a,b and # points you are pointing to the estimate parameter that can be found in the ParameterEstimates object. The coefficient of determination however can be found in the FitStatistics object.
Let's say you want to run many proc glm and append the results in a single table (actually two, considering that you will end up with one table for the estimates and one for the coefficients of determination). You can create a macro that will take the result of each proc glm and append it to a table.
%macro glm(y, x);
ods output ParameterEstimates=temp_parameters FitStatistics=temp_fit;
proc glm data=sashelp.cars;
model &y. = &x. ;
quit;
proc append data=temp_parameters base=parameters;run;
proc append data=temp_fit base=fit;run;
proc datasets lib=work nolist nodetails; delete temp_:;run;
%mend;
%glm(length, mpg_city);
%glm(length, cylinders);
%glm(length, weight);
The two final tables are created, one populated with the estimates (parameters table) and one populated with the coefficient of determination (fit table).
parameters table:
fit table:
Unfortunately, without more information about your problem and no data, I can't assist further.
Related
I am trying to show that my data has been sorted within my PROC contents output. Within this output there is an attribute called "SortedBy" and within that it shows how the contents were sorted (to the best of my knowledge).
My question is, how can I get my output to look like the below:
Here is my code:
/*Not sorted*/
proc contents data = I.projects;
run;
/*Sorted*/
proc sort data = WORK.projects out = projects;
by REGION descending POL NAME;
run;
proc contents data = WORK.projects;
run;
Select the SORTEDBY output table; as #Bill mentioned a prior submit with ODS TRACE ON will list the output tables.
proc sort data=sashelp.cars out=cars;
by descending make model type;
run;
ods select sortedby;
proc contents data=cars;
run;
Trace information appears in the SAS log
67 ods trace on;
68 proc contents data=cars;
69 run;
Output Added:
-------------
Name: Attributes
Label: Attributes
Template: Base.Contents.Attributes
Path: Contents.DataSet.Attributes
-------------
Output Added:
-------------
Name: EngineHost
Label: Engine/Host Information
Template: Base.Contents.EngineHost
Path: Contents.DataSet.EngineHost
-------------
Output Added:
-------------
Name: Variables
Label: Variables
Template: Base.Contents.Variables
Path: Contents.DataSet.Variables
-------------
Output Added:
-------------
Name: Sortedby
Label: Sortedby
Template: Base.Contents.Sortedby
Path: Contents.DataSet.Sortedby
-------------
NOTE: PROCEDURE CONTENTS used (Total process time):
real time 0.05 seconds
cpu time 0.03 seconds
70 ods trace off;
You can also retrieve the SORTEDBY data set attribute using the data step function ATTRC
data before (keep=sortedby);
when = 'BEFORE';
ds = open('cars');
sortedby = attrc(ds,'SORTEDBY');
ds = close (ds);
run;
* sort … ;
data after (keep=sortedby);
when = 'AFTER';
ds = open('cars');
sortedby = attrc(ds,'SORTEDBY');
ds = close (ds);
run;
data compare;
set before after;
run;
I am running a proc logistic with selection =score , to get the best model based on chi-square value. Here is the code
options symbolgen;
%let input_var=ABC_DEF_CkkkkkedHojjjjjerRen101 dept_gert home_value
child_household ;
ods output bestsubsets=score;
proc logistic data=trail;
model response(event='Y')=&input_var
/ selection=score best=1;
run;
The output dataset named score has been generated through ods output. Below is the image of the data set.
score data set image
In the score dataset, in the "variables included in model" column, you can only see a part of variable name "ABC_DEF_CkkkkkedHojjjjjerRen101" and not the entire name. May I know why is this happening and how do I get the entire variable name. Please let me know
Add NAMELEN=32 to your proc logistic statement.
Within an ODS POWERPOINT statement I intend to produce some output from a PROC MIXED. I do not want all the tables to be shown.
Using ODS TRACE ON passes the following results to the log:
Output Added:
Name: ModelInfo
Label: Model Information
Template: Stat.Mixed.ModelInfo
Path: Mixed.ModelInfo
Output Added:
Name: ClassLevels
Label: Class Level Information
Template: Stat.Mixed.ClassLevels
Path: Mixed.ClassLevels
Output Added:
Name: Dimensions
Label: Dimensions
Template: Stat.Mixed.Dimensions
Path: Mixed.Dimensions
Output Added:
Name: NObs
Label: Number of Observations
Template: Stat.Mixed.NObs
Path: Mixed.NObs
Output Added:
Name: IterHistory
Label: Iteration History
Template: Stat.Mixed.IterHistory
Path: Mixed.IterHistory
Output Added:
Name: ConvergenceStatus
Label: Convergence Status
Template: Stat.Mixed.ConvergenceStatus
Path: Mixed.ConvergenceStatus
NOTE: Convergence criteria met.
Output Added:
Name: CovParms
Label: Covariance Parameter Estimates
Template: Stat.Mixed.CovParms
Path: Mixed.CovParms
Output Added:
Name: FitStatistics
Label: Fit Statistics
Template: Stat.Mixed.FitStatistics
Path: Mixed.FitStatistics
Output Added:
Name: SolutionF
Label: Solution for Fixed Effects
Template: Stat.Mixed.SolutionF
Path: Mixed.SolutionF
Output Added:
Name: Tests3
Label: Type 3 Tests of Fixed Effects
Template: Stat.Mixed.Tests3
Path: Mixed.Tests3
Output Added:
Name: LSMeans
Label: Least Squares Means
Template: Stat.Mixed.LSMeans
Path: Mixed.LSMeans
NOTE: PROCEDURE MIXED used (Total process time):
real time 0.15 seconds
cpu time 0.07 seconds
...
I only want to display the outputs named "CovParms", "Tests3" and "LSMeans".
I add an ODS SELECT statement prior to the PROC MIXED as follows:
ODS POWERPOINT FILE='..\program\outputtest.pptx' nogtitle nogfootnote;
ods noptitle;
ods trace on;
--- PROCEDURES ---
ODS SELECT CovParms Tests3 LSMeans;
proc mixed data=data;
class A B C D;
model Y = X AX BX AB AB*X
/ DDFM=KENWARDROGER solution;
random CD AD;
lsmeans A*B;
run;
quit;
--- PROCEDURES ---
ODS POWERPOINT CLOSE;
However all the tables are displayed in the power point file - not only those stated in the ODS SELECT statement. The log says:
1323 ODS SELECT CovParms Tests3 LSMeans;
WARNING: Output 'LSMeans' was not created. Make sure that the
output object name, label, or path is spelled
correctly. Also, verify that the appropriate
procedure options are used to produce the requested
output object. For example, verify that the NOPRINT
option is not used.
WARNING: Output 'Tests3' was not created. Make sure that the
output object name, label, or path is spelled
correctly. Also, verify that the appropriate
procedure options are used to produce the requested
output object. For example, verify that the NOPRINT
option is not used.
WARNING: Output 'CovParms' was not created. Make sure that the
output object name, label, or path is spelled
correctly. Also, verify that the appropriate
procedure options are used to produce the requested
output object. For example, verify that the NOPRINT
option is not used.
WARNING: The current ODS SELECT/EXCLUDE/OUTPUT statement was
cleared because the end of a procedure step was
detected. Probable causes for this include the
non-termination of an interactive procedure (type
quit; to end the procedure) and a run group with no
output.
However, when I omit the other procedures I do obtain the intended output.
What it is wrong?
Any help is appreciated.
This works as expected on a test sample dataset.
ods select covparms lsmeans tests3;
proc mixed data=sashelp.cars;
class type origin;
model mpg_highway = type origin type*origin;
lsmeans type*origin;
run;
quit;
ods select all;
Adding an ods powerpoint wrapper to this also works as expected.
If this isn't working for you, I'd look at the standard issues. First try running this sample code, or a sample code that is closer to your actual data. (This is just random model I made up). If that works, look at your actual data and make sure it's not failing because of something intrinsic to the data.
how i can do if I want to assign i to intercept to make i = 906.73916.thanks
Parameter Estimates
Parameter Standard
Variable Label DF Estimate Error t Value Pr > |t|
Intercept Intercept 1 906.73916 28.26505 32.08 <.0001
acs_k3 avg class size k-3 1 -2.68151 1.39399 -1.92 0.0553
meals pct free meals 1 -3.70242 0.15403 -24.04 <.0001
full pct full credential 1 0.10861 0.09072 1.20 0.2321
ODS is very helpful for this. The names of different output components differ for different procs. Example for PROC REG below, should be about the same for most regression PROCS:
ods output ParameterEstimates=MyIntercept(where=(Variable="Intercept"));
proc reg data=sashelp.class;
model weight=age;
run;
quit;
ods output close;
proc print data=MyIntercept;
run;
How to obtain value of estimated parameters in SAS (proc phreg) ? I have been searching syntax OUTPUT and baseline but they gives only value XBETA ets.
I'm not into statistics, so I'm just guessing what value you mean - here's an example I think could help you:
ods trace on;
ods output ParameterEstimates=work.my_estimates_dataset;
proc phreg data=sashelp.class;
model age = height;
run;
ods trace off;
This is using SAS Output Delivery System component of SAS/Base.
With ods trace on;, you'll see references to parts of procedure output in SAS log:
Output Added:
-------------
Name: ParameterEstimates
Label: Maximum Likelihood Estimates of Model Parameters
Template: Stat.Phreg.ParameterEstimates
Path: Phreg.ParameterEstimates
You can refer to those (usually by Name or Path) and store them in a table with ODS OUTPUT... statement.
Look for SAS ODS user guide for more.