BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
OrnellaNdongue
Calcite | Level 5

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 !

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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.

View solution in original post

17 REPLIES 17
Kurt_Bremser
Super User

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;

?

OrnellaNdongue
Calcite | Level 5

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
Tom
Super User Tom
Super User

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).

OrnellaNdongue
Calcite | Level 5

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.

art297
Opal | Level 21

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

 

Art, CEO, AnalystFinder.com

OrnellaNdongue
Calcite | Level 5

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

 

Thank you in advance for your help !

Kurt_Bremser
Super User

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.

OrnellaNdongue
Calcite | Level 5

Here is the file with the two columns concerned.

Kurt_Bremser
Super User

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.

OrnellaNdongue
Calcite | Level 5

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.

Kurt_Bremser
Super User

@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.

OrnellaNdongue
Calcite | Level 5

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

Kurt_Bremser
Super User

@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.

art297
Opal | Level 21

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

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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