The SAS Output Delivery System and reporting techniques

prevent temporary variable from retaining

Reply
Frequent Contributor
Posts: 81

prevent temporary variable from retaining

Hello,

In proc report, by default, temporary variable created in a compute block will be retained. Is there a way to prevent this temporary variable from retaining?

e.g.

data check;
count1 = 5;
do count2 = 1 to 10;
output;
end;
run;

proc report data=check nowd;
column count1 count2;
define count1 /order order=internal;
define count2 /order order=internal;

compute before count1;
newvar = 1; *Can we prevent 'newvar' from retaining??;
endcomp;

compute before count2;
if newvar=1 then do; text='Test'; vlen=50; end; *I want to print this line only for the first obs;
else do; text=''; vlen=0;end;
line text $varying. vlen;
endcomp;
run;
Respected Advisor
Posts: 3,777

Re: prevent temporary variable from retaining

You can change that behavior of the proc but you can change the value of newvar.

[pre]
data check;
do count1 = 5,10;
do count2 = 1 to 10;
output;
end;
end;
run;

proc report data=check nowd list;
column count1 count2;
define count1 /order order=internal;
define count2 /order order=internal;

compute before count1;
newvar + 1;
endcomp;

compute before count2;
rc = seenum(newvar);
text='Test';
if newvar = 1 then do;
vlen = 50;
newvar = 2;
end; *I want to print this line only for the first obs;
else do;
vlen=0;
end;
line text $varying. vlen;
endcomp;
run;
[/pre]
Frequent Contributor
Posts: 81

Re: prevent temporary variable from retaining

this helps...thanks a lot!!!
SAS Super FREQ
Posts: 8,742

Re: prevent temporary variable from retaining

Hi:
You may not need to calculate NEWVAR at all. A simple COMPUTE BEFORE will only execute at the "top" of the report.

cynthia
[pre]
ods listing close;
ods html file='c:\temp\newvar.html' style=sasweb;

proc report data=check nowd;
column count1 count2;
define count1 /order order=internal;
define count2 /order order=internal;

compute before;
text='Test';
vlen=50;
line text $varying. vlen;
endcomp;
run;
ods html close;
[/pre]
Frequent Contributor
Posts: 81

Re: prevent temporary variable from retaining

Thanks for the reply. Actually, that was just an example. I have a complex situation where I do not want to retain the temporary variable created in the compute block. I am glad that I now have a solution for my this.
Ask a Question
Discussion stats
  • 4 replies
  • 160 views
  • 0 likes
  • 3 in conversation