Hello!
Let me see if I can explain this well. I am working on a project in my SAS class and my professor wants us to create a macro that extracts p values from our tables and use that macro to basically put in our rtf file this code:
She wants us to create the macro using call syntax and it has to just be inserted into that rtf text that I provided. My p values are in a dataset called WORK.TABLETWO and it is the p values I got from using PROC GLM and using an ANOVA test.
Here is my table two for reference:
So I guess my professor wants the p value column to be extracted using a MACRO variable using CALL SYNTAX to use in a RTF TEXT to be inserted into our RTF File.
I hope that makes sense, any advice would be helpful on how to do any of this since I am very new to macros
You will need a variable to represent the macro variable in the data set. I would name them something significant to your data.
data tablethree;
set tabletwo;
var_macro_ref = catt('Var', put(_n_, 8. -l));
call symputx(var_macro_ref, p_value);
run;
.....report code.....
ods rtf text = "Education status was not significant (P-Value = &var1.), however marijuana was significant (P-Value = &var3.)";
.... rest of report.....
Before you can write a macro you must have working code that you then modify to be a macro.
So show actual code that does what you want without any attempt at a macro.
I suspect you may have missed some bit of understanding about the requirement. For one, thing there are a fair number of Call routines in SAS but I haven't ever seen "call syntax" referenced. So I think you have substituted something else to "call syntax" in this request.
ODS RTF TEXT =" something" would not mean much unless it occurs inside of an
ODS RTF File="name of file";
/* your ods rtf text would go here */
ods rtf close;
Do you know how to get the values from your procedures into macro variables? Or into data sets which is where you would use them to make macro variables?
block of code.
Yes, here is my code to get that table that I presented:
ODS TRACE ON;
PROC GLM DATA=ANOVA;
CLASS Quartiles;
MODEL riskfactors_quartiles = Marijuana_Use Education_Status Poverty_Percent Frequent_Mental_Dist;
RUN;
QUIT;
ODS TRACE OFF;
ODS OUTPUT ModelANOVA=TableTwo;
PROC GLM DATA=ANOVA;
CLASS Quartiles;
MODEL riskfactors_quartiles = Marijuana_Use Education_Status Poverty_Percent Frequent_Mental_Dist;
RUN;
QUIT;
Then I cleaned up the table and merged it with my first table which has the means and standard deviations that was presented, but I mostly used ODS OUTPUT to manipulate my tables so it has the p value.
Let's clarify some terminology first.
Some people like to use TABLE to mean the same thing as DATASET. This terminology is very common in SQL databases. But to me a TABLE is something your include in the report you are writing about your data.
The table you showed in the photograph you posted is part of the REPORT generated by PROC ANOVA. So it is not a DATASET (yet) that you can extract data from. To get that report as a DATASET you might need to use ODS OUTPUT statement. Although I would first check the documentation of PROC ANOVA and see if it has OUT= or OUTSTAT= option that you can use to have the PROC produce a dataset directly instead of depending on ODS OUTPUT to convert the report the procedure was designed to PRINT into a dataset.
I assume the professor is asking you to use the CALL SYMPUTX() method in a SAS dataset to convert some value or values you have in a dataset into a macro variable (also call a macro symbol or just symbol). That is something different than a MACRO. A MACRO is a user defined function in the macro language that is created by the %MACRO statement and called by using % in front of the macro's name.
To reference the value of a macro variable you use & before the name of the macro variable.
CALL SYMPUTX() has two required arguments and one optional one. The first is the name of the macro variable you want store into. And the second is the value you want to store. The third is for which symbol table you want to create the amcro variable, but that is not important for this question.
So if you have a dataset named HAVE that has a variable named PVALUE and you wanted to put the value of PVALUE into a macro variable name RESULT you could use code like:
data _null_;
set have;
call symputx('result',pvalue);
run;
(Note this step only makes sense if HAVE consists of only one observation. If it has multiple observations only the value of the last observation will exist in &RESULT when the step is done).
Once you have macro variable you can use it to help generate code (in your case part of a text string in the code).
So perhaps something like this:
ods rtf text="The PVALUE was &result." ;
Note also there is an older (ancient) method named CALL SYMPUT() that you can also use. But you should only use that if you need the macro variable that is generate to contain leading and/or trailing spaces. Which is normally NOT what you want to happen.
This makes a lot more sense now, yes I was using ODS OUTPUT to create that particular dataset and I named the datasets TABLEONE TABLETWO AND TABLETHREE as part of the work library because I wanted to not confuse myself, but I guess I confused SAS communities. so that table that I presented has 4 observations so only the last one will be presented when I run that code you provided?
That's interesting and I appreciate the explanation because now it's becoming clear to me what I need to do. I may be overthinking how to get the end result but that is extremely helpful!
You will need a variable to represent the macro variable in the data set. I would name them something significant to your data.
data tablethree;
set tabletwo;
var_macro_ref = catt('Var', put(_n_, 8. -l));
call symputx(var_macro_ref, p_value);
run;
.....report code.....
ods rtf text = "Education status was not significant (P-Value = &var1.), however marijuana was significant (P-Value = &var3.)";
.... rest of report.....
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.