Hi,
My output data (.DAT) is tab-delimited (used proc export) but because some observations have different lengths columns are not properly align. Every variable/column has same length $30.
Example of my output:
How I need them to be:
I tried to use PUT statement but the output didn't change.
put second_column @20 number_column @40;
-> this means that sas will start writing second_column starting with 20th character in the line and number_column will always start at 40th character. Did I get it wrong?
I'm new to sas and I try to understand it's ways. Any tip would help, thanks!
You need to decide what you actually want. If you want all the columns to lign up then you want fixed width file format, for example:
https://communities.sas.com/t5/Base-SAS-Programming/exporting-3-datasets-into-one-fixed-width-text-f...
If you want to have tab delimited, then that will show the tab in the reader you open it with (each reader is different, for instance if you use notepad to open the file the tab might be 3 characters, open in ord it might tab differently). This is why I avoid using tab in anything - including in SAS code, as tabs render differently on different systems/applications. The underlying character is the same, but as that is a special character (like line feed and page break) it is down to the reader to render it.
You need to decide what you actually want. If you want all the columns to lign up then you want fixed width file format, for example:
https://communities.sas.com/t5/Base-SAS-Programming/exporting-3-datasets-into-one-fixed-width-text-f...
If you want to have tab delimited, then that will show the tab in the reader you open it with (each reader is different, for instance if you use notepad to open the file the tab might be 3 characters, open in ord it might tab differently). This is why I avoid using tab in anything - including in SAS code, as tabs render differently on different systems/applications. The underlying character is the same, but as that is a special character (like line feed and page break) it is down to the reader to render it.
Yes, I wanted fixed width file format.
The linked helped and the solution for me is to use put statement.
Thanks!
By definition, a delimited file cannot be aligned. You either have fixed or variable widths, and one uses delimiters to avoid fixed spacings (because of the wasted space in the file, caused by the blanks used for padding).
In a tab-delimited file, the tabs are not there to align, only to separate. What you see is not the real structure of the file, only the way the file is displayed in your current viewer. Other viewers will give you another look. So don't be worried, it's all okay.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.