BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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,
8 REPLIES 8
Chevell_sas
SAS Employee
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.
Cynthia_sas
SAS Super FREQ
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
tbatliner
Calcite | Level 5
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
Cynthia_sas
SAS Super FREQ
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]
tbatliner
Calcite | Level 5
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
Cynthia_sas
SAS Super FREQ
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
Black
Calcite | Level 5
Thank you everone here, i have learn something from this topic.
deleted_user
Not applicable
Perfect, thank you! Cynthia

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
  • 8 replies
  • 1150 views
  • 0 likes
  • 5 in conversation