BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Eva
Quartz | Level 8 Eva
Quartz | Level 8

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

1 ACCEPTED SOLUTION

Accepted Solutions
Haikuo
Onyx | Level 15

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

View solution in original post

2 REPLIES 2
Haikuo
Onyx | Level 15

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

Eva
Quartz | Level 8 Eva
Quartz | Level 8

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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

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.

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
  • 2 replies
  • 1147 views
  • 0 likes
  • 2 in conversation