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

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

1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19
PUT (_ALL_) (:) +(-1) '|';

View solution in original post

5 REPLIES 5
data_null__
Jade | Level 19
PUT (_ALL_) (:) +(-1) '|';
JohnSimmons
Calcite | Level 5

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

Haikuo
Onyx | Level 15

DN,

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

Thanks,

Haikuo

data_null__
Jade | Level 19

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, ~. 
JohnSimmons
Calcite | Level 5

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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