There are a few ways.
$line(@name,N,T)
Returns the Nth line of text in the specified window. If N is zero, it returns the total number of lines in the window.
For some reason I thought /loadbuf took lines from a window and put them in a file. On second look I guess it's the other way around.
Anyways, $line($chan,0) is total number of lines, so $line(#,$line(#,0)) will return the last line in a channel window.
set %var $line(#,$line(#,0))