Hello
I want to get list of code that will appear many times in proc report (for multiple &mj values)
I get an error
ERROR: The %DO statement is not valid in open code.
Note: I would like to run %mmmacro within proc report (use short code instead of many lines)
%macro mmmacro;
%do j=0 %to &nn.;
compute mon_&&m&j..;
if mon_&&m&j..>UCL1 and mon_&&m&j..>UCL2 then call define(_col_,"style","style={background=red}");
else if mon_&&m&j..>UCL1 and mon_&&m&j..<=UCL2 then call define(_col_,"style","style={background=lightred}");
else if mon_&&m&j..<=UCL1 and mon_&&m&j..>UCL2 then call define(_col_,"style","style={background=pink}");
endcomp;
%end;
%mend mmmacro;
%put %mmmacro;
@Ronein I see that you've posted 5 different questions within the last hour.
When I see a question on the community, I rely on the asker to have investigated the problem him/herself before posting. Is that the case? Did you spend some time Googling around or search the community for a solution to all of your questions before asking?
Don't get me wrong. It's great that you post questions and absorb knowledge from the answers you get 🙂 And people on here love to share knowledge and answer questions. However, most users want you to help yourself before we do.
Kind regards.
Hello,
You wrote 'data' instead of '%macro'.
Also, you cannot display the macro code with a simple %put as it contains semi columns
(you can use %quote to prevent them from being interpreted).
Sorry,
I have correct it but still get an error.
I understand that the reason for error is using semicolon (;)
What is the way to solve it please?
%macro mmmacro;
%do j=0 %to &nn.;
compute mon_&&m&j..;
if mon_&&m&j..>UCL1 and mon_&&m&j..>UCL2 then call define(_col_,"style","style={background=red}");
else if mon_&&m&j..>UCL1 and mon_&&m&j..<=UCL2 then call define(_col_,"style","style={background=lightred}");
else if mon_&&m&j..<=UCL1 and mon_&&m&j..>UCL2 then call define(_col_,"style","style={background=pink}");
endcomp;
%end;
%mend mmmacro;
%put %mmmacro;
@Ronein wrote:
Sorry,
I have correct it but still get an error.
I understand that the reason for error is using semicolon (;)
What is the way to solve it please?
%macro mmmacro; %do j=0 %to &nn.; compute mon_&&m&j..; if mon_&&m&j..>UCL1 and mon_&&m&j..>UCL2 then call define(_col_,"style","style={background=red}"); else if mon_&&m&j..>UCL1 and mon_&&m&j..<=UCL2 then call define(_col_,"style","style={background=lightred}"); else if mon_&&m&j..<=UCL1 and mon_&&m&j..>UCL2 then call define(_col_,"style","style={background=pink}"); endcomp; %end; %mend mmmacro; %put %mmmacro;
When you are comparing this many values, implied by having &m and &j macro variables, I suggest that it may be time to look into the Report Writing Interface instead of proc report. You can use all of the array tools to examine values and set cell styles and likely not have to result to macro codding at all.
And if the MON_ variable name implies "month" it may be that your data is structured poorly, having multiple variables with one per month instead of a single date value in long form and using the date as an "across" variable and a single analysis/report value associated with each date.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.