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