DATA Step, Macro, Functions and more

Align columns in .DAT output

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

Align columns in .DAT output

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:

 

Capture.JPG

 

 

 

 

 

How I need them to be:
Capture2.JPG

 

 

 

 

 

 

 

 

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!


Accepted Solutions
Solution
‎12-05-2017 07:38 AM
Super User
Super User
Posts: 9,227

Re: Align columns in .DAT output

Posted in reply to danacosman

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.  

View solution in original post


All Replies
Solution
‎12-05-2017 07:38 AM
Super User
Super User
Posts: 9,227

Re: Align columns in .DAT output

Posted in reply to danacosman

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.  

New Contributor
Posts: 2

Re: Align columns in .DAT output

Yes, I wanted fixed width file format.

The linked helped and the solution for me is to use put statement.

Thanks!

Super User
Posts: 9,611

Re: Align columns in .DAT output

Posted in reply to danacosman

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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 93 views
  • 1 like
  • 3 in conversation