Help using Base SAS procedures

Proc export to TXT - dash problem

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 9
Accepted Solution

Proc export to TXT - dash problem

Hello,

 

I am trying to export the table "sas_table" to a txt file. 

Here is my code :

filename export 'txt file name';

data _NULL_;

set sas_table;

file export lrecl=999999;

put @1 var1 $

@4 ";"

@5 var2 $

@6 ";"

@7 var3 $

/*

.

.

.

*/

@461 ";"

@462 var4 $

@494 ";"

;

'0D'x ;

run;

filename export;

 

When the value in the column var4 does not contain a dash, the semi-colon is at the position 494. But when the value contains a dash, the semi-colon is at the position 493. I want the semi-colon to always be at the position 494.

 

How can I fix this problem ? Thank you in advance for your help !


Accepted Solutions
Solution
‎05-30-2017 05:26 AM
Super User
Posts: 6,936

Re: Proc export to TXT - dash problem

Inspect your data.

The value "SAINT-POL-SUR-MER" actually contains a CR/LF combination immediately following the "MER". This causes a premature linebreak.

Since the following semicolon would be at position 495 by my count, I suspect that you only had a UNIX linefeed (0A) there which was expanded to the DOS CRLF upon transfer from one platform to another.

 

You can search for '0d0a'x in the strings to remove those unexpected CRLFs.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Super User
Posts: 6,936

Re: Proc export to TXT - dash problem

Since you have a delimited output anyway, why don't you use

data _null_;
set sas_table;
file "output file" dlm=';' dsd lrecl=500 termstr=CRLF;
put
  var1
  var2
  var3
  var4
;
run;

?

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Occasional Contributor
Posts: 9

Re: Proc export to TXT - dash problem

Thank you for your answer.

 

The problem is that I need to have my data ranged in columns such as in the attachment.

With the solution you propose, I don't have the expected result.

 

 


txt.png
Super User
Super User
Posts: 6,500

Re: Proc export to TXT - dash problem

[ Edited ]

What sofware are you using to read the file? Why does it want all of the extra blanks if it also wants te semi-colons?

 

PS If you want to post a picture then click on the Insert Image icon (looks like a photo of the moon over a mountain range).  If you want to post example text then then use the Insert code icon (looks like lower case letter i with curly brackets around it).

Occasional Contributor
Posts: 9

Re: Proc export to TXT - dash problem

Thank you for your answer.

 

It's a business need. I will use the txt file for the update of an informatic system.

That's why I need a specific format with extra blanks and the semi-colons.

 

Here is a screen shot of the file I obtained :

 

 

dash_problem.PNG

Let me know if you need precisions.

PROC Star
Posts: 7,363

Re: Proc export to TXT - dash problem

The png you posted doesn't show the unexpected result you described.

 

Art, CEO, AnalystFinder.com

Occasional Contributor
Posts: 9

Re: Proc export to TXT - dash problem

In fact... I put a screenshot of the problem in my precedent post.

 

Thank you in advance for your help !

Super User
Posts: 6,936

Re: Proc export to TXT - dash problem

[ Edited ]

Screenshots just document the way the file is shown by your software. They do NOT document the actual format of the file.

Please post the the FILE as attachment, making sure that the erroneously displayed lines are included.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Occasional Contributor
Posts: 9

Re: Proc export to TXT - dash problem

Here is the file with the two columns concerned.

Solution
‎05-30-2017 05:26 AM
Super User
Posts: 6,936

Re: Proc export to TXT - dash problem

Inspect your data.

The value "SAINT-POL-SUR-MER" actually contains a CR/LF combination immediately following the "MER". This causes a premature linebreak.

Since the following semicolon would be at position 495 by my count, I suspect that you only had a UNIX linefeed (0A) there which was expanded to the DOS CRLF upon transfer from one platform to another.

 

You can search for '0d0a'x in the strings to remove those unexpected CRLFs.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Occasional Contributor
Posts: 9

Re: Proc export to TXT - dash problem

You were right.

I replaced the chain '0d0a'x by a blank and it works.

 

Thank your very much for your help !

Have a great day.

Super User
Posts: 6,936

Re: Proc export to TXT - dash problem


OrnellaNdongue wrote:

You were right.

I replaced the chain '0d0a'x by a blank and it works.

 

Thank your very much for your help !

Have a great day.


Maxim 3: Know your data.

This may involve using a $hex format to find weird character codes.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Occasional Contributor
Posts: 9

Re: Proc export to TXT - dash problem

Got it ! I will check my data first when I have this kind of problem.

Super User
Posts: 6,936

Re: Proc export to TXT - dash problem


OrnellaNdongue wrote:

Thank you for your answer.

 

The problem is that I need to have my data ranged in columns such as in the attachment.

With the solution you propose, I don't have the expected result.

 

 


Does not compute. Delimiters are specifically used to enable variable-width columns and records. Using delimiters with fixed-width columns is a waste of space and brain-cycles, therefore stupid.

If you need fixed-width colums, do away with the delimiters. I can think of no software that would need both, so I smell a serious design error or misunderstanding here.

 

And the picture does not show any misplaced semicolon. I suggest posting the .txt file as attachment, and in which line the effect appears when you open the file; also post with which software you open the txt file. I also suspect that the problem lies there.

Alternatively use text editing software like notepad++ to view the file; there you can activate display in hex code, which will reveal the character sequence that leads your software astray.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
PROC Star
Posts: 7,363

Re: Proc export to TXT - dash problem

Before looking at whatever the problem might be, why does the following meaningless (by itself) statement follow the put statement?

'0D'x ;

Art, CEO, AnalystFinder.com

☑ This topic is SOLVED.

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

Discussion stats
  • 17 replies
  • 178 views
  • 2 likes
  • 4 in conversation