BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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
2 REPLIES 2
Cynthia_sas
SAS Super FREQ
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
deleted_user
Not applicable
Hi Cynthia,

It worked.
Thank you very much

Raji

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 955 views
  • 0 likes
  • 2 in conversation