Your SAS programs, embedded in web apps and elsewhere

question on getting totals on first line

Reply
N/A
Posts: 0

question on getting totals on first line

Hi,
I need totals should be printed first line for each account. Then detail lines for that account. like this for every acoount.

Ex. of output:

Assigned Liquidated Difference
$26000 1000 25000

Pos# Title Name Account
120 Faculty XXXX 26
XXXX 26
xxxx 26
total: 3

My code is :

data _null_;

length AcctSum $30;
blank = " ";
set adjunct end=no_more_data;


*file print ods=(variable=(SumAmt Sumlqu SumAdjust ));
file print ods=(variables=(Pos# title Name account));
by department;
put _ODS_;
if first.department then do;
Asum=SumAmt;
lqusum=Sumlqu;
Adjustsum=sumAmt - sumlqu;
Amtsum='Assigned: ' || put(Asum,10.0);
Lsum='Liquidated: ' ||put(lqusum,10.0);
AdSum='Difference: ' ||put(Adjustsum,10.0);
put @1 AmtSum @2 Lsum @3 AdSum;

end;
My output that I am getting Now:


Pos # Title Name Account
120 Faculty XXX 26
Assigned : 26000 Liquidated: 1000 Difference: 25000
120 Faculty XXX 26
121 Staff YYY 27
Assigned: 1000 Liquidated : 200 Difference:800
121 Staff YXY 27

Give me any suggestions

thank you
Raji
SAS Super FREQ
Posts: 8,862

Re: question on getting totals on first line

Posted in reply to deleted_user
Hi:
You seem to have a timing issue. When you have FILE PRINT ODS -- that statement acts as a pointer to the file you're creating. Then, PUT _ODS_ or any PUT statements are executed in the order in which they're encountered. So, in your case, the
[pre]
by department;
put _ODS_;
[/pre]
is writing out the observation/row info BEFORE the FIRST.DEPARTMENT info (which is further down in the program). So you could try moving the put _ODS_ underneath the END statement for FIRST.DEPARTMENT.

Remember that you are writing ONE table with a fixed number of columns on EVERY row. This means that your VARIABLES= sub-options has to refer to the variables that you want to see in the table. So, if you have 3 variables listed in the sub-option, then PUT @1 writes to the first column, PUT @2 writes to the second column, etc. Also, you must respect the types of the variables with any other PUT statements (such as those you use to write information BEFORE and/or AFTER each department) -- For example, if you had this:
[pre]
variables=(charvar numvar1 numvar2)
[/pre]
in your sub-option (1 character variable, followed by 2 numeric variables), then you could only write numeric variables to column 2 or column 3.

If you need more help with how DATA step and ODS work, you might consider contacting Tech Support.

cynthia
N/A
Posts: 0

Re: question on getting totals on first line

Posted in reply to deleted_user
Hi Cynthia,

It worked.
Thank you very much

Raji
Ask a Question
Discussion stats
  • 2 replies
  • 185 views
  • 0 likes
  • 2 in conversation