Help using Base SAS procedures

Create Text File

Accepted Solution Solved
Reply
Contributor
Posts: 67
Accepted Solution

Create Text File

Hello,

I created a text file, but for some reason, the headers return when they should be in one row.for example:

the header should be:

A  B  C  D  E  F  G  H

but the flat file I have returns:

A  B  C  D  E

F  G  H

I did notice, I got a warning saying:

"WARNING: The quoted string currently being processed has become more than 262 characters long.

                   You may have unbalanced quotation marks."

Does this cause the problem? If so, how can I fix it?

Here is my program:

proc contents data = file noprint

    out = get_varname(keep=name rename=(name=varname));

run;

Proc sql noprint;

  select varname into: Flat_head_str separated by '|'

  from get_varname;

  select varname into: Flat_var separated by ' '

  from get_varname;

FILENAME flatout "C:\SAS\test.txt";

data _NULL_;

  SET file END=EOF;

  FILE FLATOUT  DELIMITER='|' DSD;

  IF _N_=1 THEN PUT "&Flat_HEAD_STR.";

  PUT &flat_var.;

  IF EOF THEN PUT "TOTAL NUMBER OF RECORDS = " _N_;

RUN;

Thanks


Accepted Solutions
Solution
‎06-25-2015 06:53 PM
Super User
Super User
Posts: 6,500

Re: Create Text File

Is your LRECL too short to include all of the column headers?

Try adding LRECL= option to your FILE statement.

View solution in original post


All Replies
Super User
Posts: 10,500

Re: Create Text File

What program did you use to look at the resulting file? Notepad, Wordpad, Word and many other text programs will display text wrapped when the line gets to a certain length. Try looking using Notepad and set the Format -> Word wrap off by unchecking.

you might find it easier to use:

proc export data=datasource outfile=fileref dbms=dlm ;

delimiter='|';

run;

And skip the whole proc contents and macro variables bits.

I realize that you are adding a line with the number of records to the bottom but a specific delimited file makes me think this is for data interchange of some sort and lines with the number of records at the end are exceptions to the column data layout and tend to add extra processing to handle.

Solution
‎06-25-2015 06:53 PM
Super User
Super User
Posts: 6,500

Re: Create Text File

Is your LRECL too short to include all of the column headers?

Try adding LRECL= option to your FILE statement.

Contributor
Posts: 67

Re: Create Text File

Thanks Tom. It works.

☑ This topic is SOLVED.

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

Discussion stats
  • 3 replies
  • 252 views
  • 0 likes
  • 3 in conversation