BookmarkSubscribeRSS Feed
Ronein
Meteorite | Level 14

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; 

 

 

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

@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.

gamotte
Rhodochrosite | Level 12

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).

 

Ronein
Meteorite | Level 14

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; 
ballardw
Super User

@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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 4 replies
  • 362 views
  • 1 like
  • 4 in conversation