The SAS Output Delivery System and reporting techniques

Exporting to text file

Reply
N/A
Posts: 0

Exporting to text file

Hi All,
I trying to produce a list report to text file which displays all variables and getting formatted.
I can do it with proc print.
Foexample;
proc print data=murti;
var name surname job birth;
run;
Result output;
/******************************************************
name surname job birth
. . .
. . .
. . .
******************************************************/
But when I define length and format it isn't seems same rows;
forexample:

proc print data=murti;
format name surname job $50. birth 4.;
var name surname job birth;
run;

Result Output;
/****************************************************
name surname
. .
. .
. .

job birth
. .
. .
. .

How can I see this values in same rows?
I have to export only like *.txt,
Best regards,
SAS Employee
Posts: 88

Re: Exporting to text file

With PROC PRINT or any of the procedures, you are limited to what can be written to a single line by the maximum line size which is 256. You can try to increase the line size with the LS= system option. If you need more than 256, then you can use DATA _null_ with the FILE/PUT statements.
SAS Super FREQ
Posts: 8,743

Re: Exporting to text file

Here's an example of using the FILE statement and DATA _NULL_ -- you can write columns that will "line up" or formatted by using column pointer control in the PUT statement to explicitly place every character/byte in the .txt file:
[pre]
data _null_;
set sashelp.class;
file 'c:\temp\class.txt';
if _n_ = 1 then do;
** write out column names;
put @1 "Name"
@15 "Age"
@25 "Height";
end;
** write out every obs;
put @1 name $char15.
@15 age 3.0
@25 height 5.2;
run;
[/pre]

after this program runs, you can open class.txt in Notepad and see the columns line up (as long as the Notepad font is set to Courier -- if you use a proportional font to view, then the columns will not look lined up.)
cynthia
Contributor
Posts: 30

Re: Exporting to text file

Hi all,

how can I write entries to the external file if the text contains spaces and/or special character? I have to copy/delete external files on our SAS-Server with paths like "\\sasserver\filedir" and filenames containing blanks i.e. "File 1.csv"?

I tried:

%let docopy=docopy.bat;
data _null_;
file docopy notitles noprint lrecl=1000;

statement = 'copy '||&fromdir.||&copyfile.||' &todir.';
put @1 statement;
run;
data _null_;
x &docopy.;
run;

But SAS wont write the file...

Thx in advance,
Tom
SAS Super FREQ
Posts: 8,743

Re: Exporting to text file

Hi:
Your X command does not need to be in a DATA _NULL_ program. You may need to investigate some of the options that affect the X command, (NOXWAIT and NOXSYNC)

However, this is not really an ODS or BASE Reporting procedure question. The SAS companion for your operating system gives different ways to execute statements in command or exec file.

For example, if I wanted to have SAS issue an X command to start Word from within a SAS session (sort of a silly example), I could do this (note that there is no data step program in this code at all):
[pre]
options noxwait noxsync;
x 'C:\Program~1\Micros~2\Office\winword.exe';
[/pre]
or, if I want to clean up a file before I start my program, I can do this:
[pre]
x 'del c:\temp\oldfile.txt';
[/pre]
Your best bet for help with this question is to read the documentation for examples of the X command or to contact Tech Support for more help.

cynthia
[/pre]
Contributor
Posts: 30

Re: Exporting to text file

Hi cynthia,

thx for the fast reply. I just managed to solve my problem:
[pre]
%let vgbatfile=copyvgfiles.bat;

filename vgbat "J:\temp\&vgbatfile.";

data _null_;
file vgbat lrecl=1000;

statement = 'move "'|| "&fromdir."|| '\'|| trim("&fromFilename.")||'" "'||"&todir."||'"';
put statement @;

run;

filename vgbat pipe "J:\temp\&vgbatfile.";
data _null_;
infile vgbat ;
input;
run;
[/pre]

I think the "trick" was to use the correct "put" statement with the "@" at the end.

Best regards,
Tom
SAS Super FREQ
Posts: 8,743

Re: Exporting to text file

Hi:
I'm glad that worked for you. But I'm still baffled why your BAT file needs to be in a DATA step. I just double checked and my test BAT file executes just fine like this:

[pre]
filename copylist 'c:\temp\mycopylist.bat';
** copy and add zz in front of the new file name;
** if you want to run this, change my FROM and TO and my filenames;

data _null_;
length fromfile tofile $200 fromdir todir fname $100;
infile datalines;
input fromdir $ todir $ fname $;
fromfile = catt(fromdir,'\',fname);
tofile = catt(todir,'\zz',fname);
file copylist;
if _n_ = 1 then put 'echo off';
put @1 'copy ' fromfile tofile;
return;
datalines;
c:\temp c:\temp\mydata kermit.jpg
c:\temp c:\temp\mydata myanswers.doc
;
run;

filename copylist clear;

* Then issue the X command *;
options noxwait noxsync;
x 'c:\temp\mycopylist.bat';[/pre]

But there's always more than one way to do something with SAS...so I learned something new today!

cynthia
Occasional Contributor
Posts: 13

Re: Exporting to text file

Thank you everone here, i have learn something from this topic.
N/A
Posts: 0

Re: Exporting to text file

Perfect, thank you! Cynthia
Ask a Question
Discussion stats
  • 8 replies
  • 308 views
  • 0 likes
  • 5 in conversation