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-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
  • 4 replies
  • 8744 views
  • 0 likes
  • 4 in conversation