DATA Step, Macro, Functions and more

CSV Export - No CR/LF

Accepted Solution Solved
Reply
Contributor
Posts: 23
Accepted Solution

CSV Export - No CR/LF

Hey all!  Thank you in advance for reading and thank you doubly should you try and assist.

So I am trying to export a CSV file with no header row, ~ as the delimiter, and a | character (I think this the pipe character) as the record delimiter.

So I have this wrapped up in a macro:

FILENAME dlmTest &fileName lrecl=50000;

DATA _NULL_;

    SET &dataSet;

    FILE dlmTest

        DSD

        RECFM=N

        LRECL=50000

        DLM='~';

    PUT (_ALL_) (+0);

RUN;

I found, as part of the FILE syntax, RECFM but I'm running into a series of problems.

The file always automatically inserts the CRLF when generating unless I have RECFM=N

    (the option for fixed length won't work, since my fields are variable length).

When I use RECFM=N, it would almost work except it adds an additional ~ after each line.

As part of my data set, I found I could add a column that just put in the pipe I needed as I didn't see an obvious way to add this in normally.

My question ultimately is how to generate, for multiple records, a single line of output for a CSV without CRLF automatically added and without adding the extra ~ to the end of the record.

Thanks for any help you can provide!

John


Accepted Solutions
Solution
‎01-23-2013 08:03 PM
Respected Advisor
Posts: 3,799

Re: CSV Export - No CR/LF

Posted in reply to JohnSimmons
PUT (_ALL_) (Smiley Happy +(-1) '|';

View solution in original post


All Replies
Solution
‎01-23-2013 08:03 PM
Respected Advisor
Posts: 3,799

Re: CSV Export - No CR/LF

Posted in reply to JohnSimmons
PUT (_ALL_) (Smiley Happy +(-1) '|';
Contributor
Posts: 23

Re: CSV Export - No CR/LF

Posted in reply to data_null__

data _null_,

Thank you very much for your help, that worked perfectly!

Now I am off to go read why that worked.

Thanks again!

John

Respected Advisor
Posts: 3,156

Re: CSV Export - No CR/LF

Posted in reply to data_null__

DN,

I look up some docs, but still not 100% positive on the usage of (Smiley Happy. Is its purpose to add a blank after each variable?

Thanks,

Haikuo

Respected Advisor
Posts: 3,799

Re: CSV Export - No CR/LF

In order to put (_ALL_) in parenthesis, in order to switch its meaning from "put program data vector" to "variable list" we need to follow with the parenthesized list of (format specifications/pointer control).  The OP used +0 for the same reason but for some unknown reason I don't like +0.

I can't be nothing.

24            PUT (_ALL_) () +(-1) '|';
                          
_
                          
22
ERROR
22-322: Syntax error, expecting one of the following: a quoted string, a format name, $, &, /, //, :, =, ?, OVERPRINT, ~. 
Contributor
Posts: 23

Re: CSV Export - No CR/LF

Posted in reply to data_null__

To arrive at an understanding of the syntax of what data _null_; originally supplied, I utilized the following two documents:

SAS(R) 9.2 Language Reference: Dictionary, Fourth Edition

http://www2.sas.com/proceedings/sugi26/p073-26.pdf

I was looking in the wrong place for what I was trying to do, trying to manipulate the file instead of what was actually being put into the file - that was my mistake.

Now I am much more enlightened to the extent and power of the PUT statement thanks to DN and this wonderful documentation.

Thanks again!

John

🔒 This topic is solved and locked.

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

Discussion stats
  • 5 replies
  • 1089 views
  • 0 likes
  • 3 in conversation