BookmarkSubscribeRSS Feed
imdickson
Quartz | Level 8

Hello, Im using SAS EG to do PROC REPORT.

I have a problem here. I have managed to add Obs into PROC REPORT however, the Obs appears until the very last row of the table which is already at the SUM/TOTAL row. I want my obs up to the last row before SUM. Is there a way to do so?

PROC PRINT OBS.jpg

 

My code:

proc report data=WORK.JOIN2BCAE;
COL obs X_BCAE_NAME X_BCAE_POSITION X_BCAE_INCOME X_BCAE_CARLOAN X_BCAE_MORTGAGE X_BCAE_CASHFLOW /*newsum*/ newcompute;

define obs / computed "No.";
define X_BCAE_NAME / display "Name";
define X_BCAE_POSITION / display "Position";
define X_BCAE_INCOME / sum "Income";
define X_BCAE_CARLOAN / order sum "Car Loan";
define X_BCAE_MORTGAGE / analysis "Mortgage";
define X_BCAE_CASHFLOW / analysis "Cash Flow";
define newcompute / computed "Maximum New Loan";
compute newcompute;
newcompute=X_BCAE_INCOME.sum-X_BCAE_CARLOAN.sum-X_BCAE_MORTGAGE.sum-1500;
ENDCOMP;
compute obs;
dsobs +1;
obs=dsobs;
endcomp;
/*compute CARLOAN;*/
/*CARLOAN=CARLOAN.SUM;*/
/*ENDCOMP;*/


/*compute X_BCAE_POSITION; */
/*if _break_ ne ' ' then call define('age','style','style=[pretext="total"]'); */
/*endcomp; */

compute after;
       X_BCAE_POSITION='TOTALS:';
    endcomp;
	rbreak after  /skip summarize dol dul;

RUN;

 

 

 

13 REPLIES 13
Kurt_Bremser
Super User

Add the observation number to the dataset in a previous step, and use it with type "display" in proc report. This keeps it from appearing in the summary line.

imdickson
Quartz | Level 8

Hi Kurt, u mean before compute, do 1 datastep to store the number of records? for example 1 to 9 if my records has 9 rows?

imdickson
Quartz | Level 8
just to ask again, this datastep is outside PROC REPORT or within PROC REPORT? because if i put in PROC REPORT, all my compute shows red color and error....
Kurt_Bremser
Super User

The data step would have to happen separately before proc report.

But I found a better way:

compute obs;
dsobs + 1;
if _break_ ne ' ' then call define('obs','style','style=[pretext=""]'); else obs = put(dsobs,best.);
endcomp;
imdickson
Quartz | Level 8
i think this works like ur sample code:
compute obs;
if _break_ ne '_RBREAK_' then dsobs +1;
obs=dsobs;
endcomp;
Kurt_Bremser
Super User

In my test

proc report data=sashelp.class;
col obs name weight;
define obs / computed "No.";
define name / display 'Name';
define weight / analysis 'Weight';
compute obs;
if _break_ ne '_RBREAK_' then dsobs +1;
obs=dsobs;
endcomp;
rbreak after /summarize;
run;

this only prevented the increment, but still displayed the number of the previous step

This worked better:

compute obs;
if _break_ ne '_RBREAK_' then do;
  dsobs +1;
  obs=dsobs;
end;
endcomp;

I think this is the most elegant (bc. simple) solution.

imdickson
Quartz | Level 8
Hi Kurt, however, in the results, there is a .(which indicates a null) in the TOTAL/SUM row. Any idea on how to eliminate that?
Kurt_Bremser
Super User

@imdickson wrote:
Hi Kurt, however, in the results, there is a .(which indicates a null) in the TOTAL/SUM row. Any idea on how to eliminate that?

Ah, I had options missing = ' '; active.

Add

options missing = ' ';

before the proc report.

 

Ksharp
Super User

Not tested. This could worked ?

 


options missing=' ';
................
compute after; X_BCAE_POSITION='TOTALS:'; obs=. ; endcomp;
imdickson
Quartz | Level 8
where exactly do i put this options missing=' '; ?
Ksharp
Super User

At the start of your code. It is system option.

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 13 replies
  • 1595 views
  • 0 likes
  • 3 in conversation