If I extract source code from a SAS catalog entry of type source, all the lines are padded with spaces to the LRECL value which defaults to 128. Therefore, when you copy and paste the source code to print it, the lines come out as double spaced due to the line length.
This is where the $VARYING. format comes into play. In the below code, the input file is read in as $CHAR256. to retain the leading spaces then the line LENGTH() is determined after trailing spaces have been removed with the TRIM() function. That line length value (len) is added to the $VARYING. format which will now keep my leading spaces or indentation and remove the trailing spaces.
The CLIPBRD (clipboard) access method is used so that the contents are written to the computer's clipboard so that the trimmed contents can be pasted to whatever destination you desire.
filename xin catalog "lib.cat.entry.source" ; filename xout clipbrd ; data _null_ ; infile xin ; file xout ; input line $char256. ; len = length( trim( line ) ) ; put line $varying256. len ; run ; filename xin clear ; filename xout clear ;