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
SAS Super FREQ
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.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 1231 views
  • 0 likes
  • 3 in conversation