BookmarkSubscribeRSS Feed
B_rad
Calcite | Level 5


Hello,

 

I am working in Enterprise Guide 7.1 and trying to put a carriage return at the end of my dataset (the last line of my file), which I am outputting as a text file. However I am not sure the correct syntax to do the carriage return for the end of my dataset (last line of the file). The dataset will always have 37 variables and be a length of 304, but the number rows will change week to week. I am fairly new to this so certainly if I can clarify, I welcome any assistance. Thank you! Here is what I have.

 

options missing=' ';

data _NULL;

File "/path/path/File_name.txt";

set work.file;

put

@1 Variable $2.

@3 Variable2 yymmddS10.

...

@300 Variable 37 $4.;

run;

 

Thank you !

2 REPLIES 2
Tom
Super User Tom
Super User

SAS already writes an end of line character at the end of every line it writes to a text file.

 

Also it looks like you are using Unix. On Unix file system text files normally use LineFeed as the end of line markers as apposed to Windows file systems that use CarriageReturn and LineFeed as the end of line markers.  You can change this by using the TERMSTR= option on the FILE statement.

 

Why do you want to add an extra carriage return at the end of the file?

If you really just want to write an extra empty line at the end of your file the add an extra PUT statement that runs only on the last observation.

 

Note you don't need the @ 1 since SAS always starts writing at the first position unless you tell it otherwise.  You also don't need the @ 3 since you just wrote two characters into columns 1 and 2 so the pointer is already at column 3.

 

data _null_;
  file "/path/path/File_name.txt";
  set work.file end=eof;
  put  Variable $2. Variable2 yymmddS10.
          ...
         @300 Variable37 $4.
  ;
  if eof then put;
run;
B_rad
Calcite | Level 5

Thank you for the quick response Tom, i appreciate the detailed explanation and suggestions.  My client is asking for a carriage return to meet their specific design when they import the data.  This item is the last part of this project so hopefully this solution can close out this job. Thank you again.

 

Regards ~ B_rad

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 2445 views
  • 0 likes
  • 2 in conversation