BookmarkSubscribeRSS Feed
Phero
Calcite | Level 5
I'm wondering if it is possible to preferentially print information to a file when running many different stats. I'm not great with SAS, so this code may be completely unintuitive, but this is kind of the framework that I'd like to use.

PROC IMPORT OUT= WORK.dataset DATAFILE= "inputfile.csv"
REPLACE;
RUN;
DATA Work.dataset;
SET Work.dataset;

* performs the glm ;
proc glm data=work.dataset; ods exclude multistat; model var1 var2 = /nouni; repeated TrialType 2;


*writes the ModelANOVA table to its own dataset ;
ods output ModelAnova=work.ma1;

* opens the new dataset which is the ModelANOVA table;
data work.ma1; set work.ma1;
if source EQ 'TrialType' and ProbF < .10 then do;
-------This is the place where I would like to print the table----
end;
run;

* performs the glm ;
proc glm data=work.dataset; ods exclude multistat; model var3 var4 = /nouni; repeated TrialType 2;
*writes the ModelANOVA table to its own dataset ;
ods output ModelAnova=work.ma2;

* opens the new dataset which is the ModelANOVA table ;
data work.ma2; set work.ma2;
if source EQ 'TrialType' and ProbF < .10 then do;
-------This is the place where I would like to print the table-----
end;
run;
quit;


So, basically, I would like to print the ANOVA table for each GLM procedure ONLY if certain conditions are met (ProbF < .10). In some cases, I would be doing 50+ procedures in a row of this manner, and I would only like to kick out the ANOVA tables (work.ma1, work.ma2, etc.) if there turns out to be a significant difference.

Essentially, what I would like to end up with is a single CSV file that contains only the ANOVA tables for significant findings. Is this possible?
5 REPLIES 5
Phero
Calcite | Level 5
Also, I apologize for the multiple posts. Apparently hitting "back" and then "post" doesn't edit the post, but instead creates a new one. Sorry again! Message was edited by: Phero
Cynthia_sas
SAS Super FREQ
Hi:
Almost any SAS procedure can use a WHERE statement to limit the rows processed. So, assuming that the output from PROC GLM contains the variables SOURCE and PROBF, then you should be able to just use PROC PRINT with a simple WHERE statement. For more sophisticated or automated generation of output, you might consider using SAS macro processing, but a simpler approach would involve running all your GLM steps and creating your output files and then doing a PROC PRINT on your created datasets. Only the PROC PRINT steps are shown below.

cynthia
[pre]
** Run your GLM steps, create your output datasets and then if you;
** want all the output datasets in 1 CSV file, use PROC PRINT;
** at the end of the GLM steps.;
** You can use a WHERE statement with SAS procedures to limit the rows;
** handled by the procedure.;

ods csvall file='c:\temp\all_MA_info.csv';

proc print data=work.ma1;
title 'Work.MA1';
where source EQ 'TrialType' and ProbF < .10;
run;


proc print data=work.ma2;
title 'Work.MA2';
where source EQ 'TrialType' and ProbF < .10;
run;

ods csvall close;
[/pre]
Phero
Calcite | Level 5
Thanks for your help. I had tried using the 'where' statement but, for some reason, I was having a hard time grappling with it until I saw your code.

A quick followup question: Is there any (relatively simple) way to have it print the entire table (work.ma1, work.ma2, etc), if any one of the ProbF values is < .10?

For example, say that I have a table where Source='TrialType' and ProbF < .10
Can I have it print the whole table in this circumstance, even where Source NE 'TrialType'?

I'm thinking of this specifically for when I include predictor variables, when a table is produced with the predictor as a source, 'TrialType', and TrialType * Predictor. That way, if any one of the ProbF values is < .10, I would be able to just print the whole table instead of just the lines from the table where ProbF < .10.
Cynthia_sas
SAS Super FREQ
Hi:
I guess without delving more into the structure of the output dataset from GLM, I'd have to say, "it depends" -- it depends on whether there is a variable named PROBF, it depends on whether that variable contains the number you want on every row of the table and it depends on what you mean by "entire" table.

Simply changing the WHERE statement might be enough:
where ProbF < .10;

However, that would only return the rows on which the ProbF variable was actually LT .10; however, you may just as well have a column called _STAT_ and another column called _VALUE_ (hypothetical names) and, on one row the value of _STAT_ was the character string 'ProbF' and _VALUE_ was .10 and on another row, the value of _STAT_ was the character string 'ProbT' and the _VALUE_ was .0000001 (fake example for ProbT). Since GLM is not one of my "go to" procedures, I'm not familiar with the structure of the output datasets.

All I can say is you'll have to test it out and see whether a simple WHERE will work, given the structure of the GLM output. As I said before, more sophisticated processing is possible, such as the situation where you need to read something from the dataset, make your decision and then do your PRINT -- this might be a job for using SAS Macro processing and the SAS Macro facility.This paper is a good overview of the SAS Macro facility and has some examples of conditional processing.
http://www2.sas.com/proceedings/sugi28/056-28.pdf

My standard warning is to explore all possible non-Macro solutions, especially if you are a beginner, before you go down the Macro road and if you decide you do need to use SAS Macro, then start from a WORKING SAS program -- the SAS Macro facility only generates code to send forward to the compiler -- if your starting point code is broken, the Macro facility will then generate broken code.

cynthia
Ksharp
Super User
Hi.
Quick view .
I think you need proc append which can append all the dataset you want(source EQ 'TrialType' and ProbF < .10) into one dataset ,then use proc export to output a csv file.
Such dummy code like this:


Instead your following code with my code :

* opens the new dataset which is the ModelANOVA table;
data work.ma1; set work.ma1;
if source EQ 'TrialType' and ProbF < .10 then do;
-------This is the place where I would like to print the table----
end;
run;

[pre]
data base; *Only After the first proc glm ,do it. It create a base table just like table ModelAnova;
set work.ma2;
stop;
run;

proc append base=base dataset=work.ma2(where=(source EQ 'TrialType' and ProbF < .10) force;
run;*do it, after every proc glm include the first proc glm;





Ksharp

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 890 views
  • 0 likes
  • 3 in conversation