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!
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;
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:
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
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 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.