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

Hi guys,

I have a problem when running this code to generate SQL data into report text format because it has a spacing problem in which sentences or words are being separated onto separate lines instead of flowing smoothly across (sample attached). I know it is a concatenation issue and have tried the options ls (linespace) and options ps (pagesize) but they have not helped. Does anyone have any suggestions?

Many thanks,

*Bringing in SQL tables into SAS format;

**Set DBMAX to longest character length in data field;

libname testsql oledb

init_string="Provider=SQLOLEDB.1;

Integrated Security=SSPI;

Persist Security Info=True;

Initial Catalog = 201107014D;

Data Source=vhacdwrb01.vha.med.va.gov"

Schema= dflt

DBMAX_Text= 10000;

*Getting sample into SAS dataset;

data batch3;

    set testsql.TIU_Batch3_wText;

    keep Source Sta3n DocumentIEN ReportText;

run;   

*Exporting SAS dataset to txt files;

data _null_;

    set batch3;

    _filename= cats("\\vhacdwfpcfs02\Projects\201107014D\Annotation\TIU Reports\Batch 3\",Source,"_",Sta3n, "_",DocumentIEN)||'.txt';

    file dummy filevar= _filename;

    put Source= ;

    put;

    put Sta3n= ;

    put;

    put DocumentIEN= ;

    put;

    put ReportText= ;

run;

1 ACCEPTED SOLUTION

Accepted Solutions
bentleyj1
Quartz | Level 8

I would have thought that thlog would have a message about the wrapping.  Very curious.

Your filename does not specify a record length, LRECL, but the libref specifies max length=10000.  As I recall, the default output record length is 256 and wrapping occurs after that.  Maybe you need to add LRECL=10000 to your fileref so that it looks like

     file dummy filevar= _filename lrecl=10000;

If this doesn't solve the problem, perhaps provide a few records from your work.batch3 data set for us to play with.

View solution in original post

5 REPLIES 5
Patrick
Opal | Level 21

The output you're giving us in the attachment hasn't been created with the code you've posted. So I'm not really sure what I'm looking at.

To use multiple 'put' statements writing text onto the same line of output you need to use syntax like 'put <variable> @;'  - else each put statement will start on column 1 of a new line.

But I actually assume what disturbes you is that the output of variable 'ReportText' breaks over multiple lines. Have you checked that these line breaks are not already in the source data?

JY2013
Calcite | Level 5

Hi Patrick,

Thanks for your response. Yes you are right, the Report Text being separated across multiple lines is the issue. I have checked that the source data is perfectly normal so I know it definitely has something to do with the code.  I have tried putting the put <variable> @; as you suggested but it did not return favorable results.

Anyone encounter similar problems before?

Thanks,

Jane

Tom
Super User Tom
Super User

Use the LRECL option on the FILE statement to set the line length.  The default is only 256.

bentleyj1
Quartz | Level 8

I would have thought that thlog would have a message about the wrapping.  Very curious.

Your filename does not specify a record length, LRECL, but the libref specifies max length=10000.  As I recall, the default output record length is 256 and wrapping occurs after that.  Maybe you need to add LRECL=10000 to your fileref so that it looks like

     file dummy filevar= _filename lrecl=10000;

If this doesn't solve the problem, perhaps provide a few records from your work.batch3 data set for us to play with.

JY2013
Calcite | Level 5

Thank you for your clear and concise explanation! It appears to be wrapping correctly now Smiley Happy

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 1116 views
  • 4 likes
  • 4 in conversation