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

I am trying to create .txt output with column names and output in columns.  I've tried Proc Export, Data _null_ with Puts, ODS (multiple versions).  The results I keep getting returned is warped text.  I need columns.

 

Here are 3 of my many attempts:

 

proc export data=sashelp.class

  outfile="/home/jm25324/class.txt"

  dbms=tab replace ;

run;

 

 

data _null_; set sashelp.class ;

  file '/home/jm25324/test.txt' dlm=",";

  If _n_=1 then do;

     put 'Name, Sex, Age, Height, Weight';

  end;

  put name sex age height weight;

run;

 

ods csvall file='/home/jm25324/test5.txt' ;

proc report data=sashelp.class nocenter headline headskip spacing=10 nowd;

column name sex age height weight;

define name / display order "Name" left width=40 ;

define sex / display "Sex" left width=40 flow;

define age / display "Age" left width=40 flow;

define height / "Height" left width=40 flow;

define weight / "Weight" left width=40 flow;

run;

ods csvall close;

 

Thanks!

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
jeninemilum
Fluorite | Level 6
Here is the solution using the options TERMSTR=crlf:

data _null_;
set sashelp.class ;
file '/home/jm25324/test6.txt' TERMSTR=crlf;
If _n_=1 then do;
put @1 'Name' @ 20 'Sex' @25 'Age' @30 'Height' @40 'Weight';
end;
put @1 name @ 20 sex @25 age @30 height @40 weight;
run;

View solution in original post

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

You can use the column pointer @ like this

 

data _null_; 
  set sashelp.class ;
  file '/home/jm25324/test.txt';
  If _n_=1 then do;
     put @1 'Name' @ 20 'Sex' @25 'Age' @30 'Height' @40 'Weight';
  end;
  put @1 name @ 20 sex @25 age @30 height @40 weight;
run;
Cynthia_sas
SAS Super FREQ

Hi:

  I'm not sure of the purpose of fixed width columns with a comma separator. Do you mean something like this? I'd do it using full control of my PUT statements:

fixed_width_and_comma.png

I don't really understand what you mean when you say "with column names and output in columns" but this is how I interpreted it.

 

Cynthia

jeninemilum
Fluorite | Level 6
Here is the solution using the options TERMSTR=crlf:

data _null_;
set sashelp.class ;
file '/home/jm25324/test6.txt' TERMSTR=crlf;
If _n_=1 then do;
put @1 'Name' @ 20 'Sex' @25 'Age' @30 'Height' @40 'Weight';
end;
put @1 name @ 20 sex @25 age @30 height @40 weight;
run;

ballardw
Super User

Fixed column normally means something like variable 1 will occupy columns 1 through 10, variable 2 columns 11 to 17, variable 3 columns 18 to 25 for example and no specific character between values though spaces occur if the length of the variable value is smaller than the space used.

Is that what you want? You are showing comma separated values in your header row in the data _null_ data step and requesting comma separated columns in for the proc report output.

 

Perhaps you are looking for something like:

ods listing file='/home/jm25324/test5.txt';
proc print noobs data=sashelp.class;
run;
ods listing close;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 9225 views
  • 0 likes
  • 4 in conversation