BookmarkSubscribeRSS Feed
NickR
Quartz | Level 8
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;
4 REPLIES 4
data_null__
Jade | Level 19
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]
NickR
Quartz | Level 8
this helps...thanks a lot!!!
Cynthia_sas
Diamond | Level 26
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]
NickR
Quartz | Level 8
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.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1657 views
  • 0 likes
  • 3 in conversation