Loop within compute block in Proc Report

Accepted Solution Solved
Reply
Contributor
Posts: 40
Accepted Solution

Loop within compute block in Proc Report

Hello,
I am trying to incorporate a loop into a compute block within proc report. The column number is based on the formula "2s+5" in my loop below. Therefore I need to create another variable that is equal to 2s+5. Also, I am not sure if I can create a macro variable and then plug it in for the column number, where I have <?> below. Any help on this is greatly appreciated.

 

Part of the compute block code:

compute Score;
%do s = 1 %to &NumTPs;

if _c<?>_ eq '.' or _c3_ eq '.' then
call define('_c<?>_', "style",
"style=[backgroundcolor=white color=black]");
else if _c<?>_ >= _c5_ and _c3_ ne '.' then
call define('_c<?>_', "style",
"style=[backgroundcolor=#403151 color=white]");
.....

%end;
endcomp;


Note: I have the code working without the loop.

Thanks,
KelseyB


Accepted Solutions
Solution
‎10-21-2015 07:44 PM
Grand Advisor
Posts: 10,211

Re: Loop within compute block in Proc Report

It's really a good idea to show the whole code.

 

Do you mean

%do s= 1 to &Numtps;

   %let temp= %eval(2 * &s +5);

 

   if _c&temp._ eq '.' or _c3_ eq '. ' then

       call define("_c&temp._", ...     <= not use of " or else the &temp won't resolve

View solution in original post


All Replies
Solution
‎10-21-2015 07:44 PM
Grand Advisor
Posts: 10,211

Re: Loop within compute block in Proc Report

It's really a good idea to show the whole code.

 

Do you mean

%do s= 1 to &Numtps;

   %let temp= %eval(2 * &s +5);

 

   if _c&temp._ eq '.' or _c3_ eq '. ' then

       call define("_c&temp._", ...     <= not use of " or else the &temp won't resolve

Contributor
Posts: 40

Re: Loop within compute block in Proc Report

Thanks BallardW.  That does the trick!   Also, I appreciate you pointing out to use the double quotes instead of the single quotes on the call define statement.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 234 views
  • 0 likes
  • 2 in conversation