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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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