Dear all,
I have a proc report:
proc report data=mydata;
column myfield1 myfield2;
define myfield1 / group;
define myfield2 / computed;
[..]
run;
where the values of myfield2 are either 1 oder 0.
I'd like to have now a myfield3 which ist the aggregated value of myfield2. That means, myfield3 should have the values 1 , 2, 3, 4, etc. and 1 is added as soosn as myfield2 is 1.
This is like retain in the data step. But when I use retain in a compute statement for myfield3 I get an error implicating that I can't use retain here.
Unfortunately I cannot use a data step with retain before the proc report (which is much more complicated than the simle example here) to solve the problem as myfield2 can only be computed in the proc report.
Is there any way to do this?
Best wishes
Eva
Hi Eva,
Since reported items are not retained, you would need a non-report temporary variable to retain the value: The following code is just to show how to retain a variable of interest.
proc report data=sashelp.class nowd headline out=tst1;
column sex age height weight age=no col_a;
define sex / group;
define height / analysis mean;
define no / analysis n "Count"format=comma12.0;
compute col_a;
temp1+height.mean*no;
col_a=temp1;
endcomp;
run;
Say You want to retain col_a, but you can't do it directly by using retain or summary function, however, if you introduce a new Non-reported variable 'temp1', then you get your workaround.
HTH,
Haikuo
Hi Eva,
Since reported items are not retained, you would need a non-report temporary variable to retain the value: The following code is just to show how to retain a variable of interest.
proc report data=sashelp.class nowd headline out=tst1;
column sex age height weight age=no col_a;
define sex / group;
define height / analysis mean;
define no / analysis n "Count"format=comma12.0;
compute col_a;
temp1+height.mean*no;
col_a=temp1;
endcomp;
run;
Say You want to retain col_a, but you can't do it directly by using retain or summary function, however, if you introduce a new Non-reported variable 'temp1', then you get your workaround.
HTH,
Haikuo
Dear Haikuo,
thanx for the answer and the general rule that report items cannot be retained but temporary variables. That's a godd rule to keep in mind.
So when I run the example I see that the temporary variable temp1 was initialized with 0. I then thought about initializing it with another value and this is what works:
compute before;
temp1 = 100;
endcomp;
Best wishes,
Eva
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.