Your SAS programs, embedded in web apps and elsewhere

question on getting totals on first line

Posts: 0

question on getting totals on first line

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
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;
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;

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
Posts: 8,862

Re: question on getting totals on first line

Posted in reply to deleted_user
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
by department;
put _ODS_;
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:
variables=(charvar numvar1 numvar2)
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.

Posts: 0

Re: question on getting totals on first line

Posted in reply to deleted_user
Hi Cynthia,

It worked.
Thank you very much

Ask a Question
Discussion stats
  • 2 replies
  • 2 in conversation