hi,
I had a couple of questions around ASCII file:
PROC EXPORT
DATA=libname.data
OUTFILE="D:\xyz\test.asc"
DBMS=tab REPLACE;
run;
Any help will be appreciated! Thanks!
I don't understand what you mean by blocks of variables but you can on an input statement use things like:
input Var1-var500 Varb1-Barb500;
Which will read the data into Var1 var2 var3 var4 ... var500 Varb1 Varb2 Varb3 .... Varb500
PROC EXPORT has minimal control over output, one it doesn't is variable order on export. You are getting tabs because you requested them in the DBMS=tab statement.
The old school to give you complete control over output to ascii is to use a data _null_, file and put statements. If you want to create fixed column output then there are ways using column pointers to specify either absolute or relative spacing between variables, which formats to use to control appearance of values in the output.
Data _null_;
file "C:\my text file.txt" lrecl=<a value at least as large as the number of columns you expect>;
set datasetname;
put var1-var500 ;
run;
In addition to the response above, you can provide a little more detail. For example, when reading data into SAS from ASCII, you can use the LENGTH statement:
LENGTH V1-V500 $6 V501-V700 8 V701-V900 $1;
INPUT V1-V900;
You can control the delimiter for the input or output file by using the DLM option:
FILENAME TEXT "my documents\stuff\things.txt";
DATA WHATEVER;
INFILE TEXT DLM="|" DSD LRECL=9999 MISSOVER;
INPUT V1-V900;
RUN;
DLM tells SAS what to use as a separator; DSD tells SAS that consecutive separators imply a missing value. I always identify the input record length, because early on PC-SAS defaulted to (I seem to recall) 256 characters.
You can use the DLM option on your FILE statement as well. As ballardw notes, you need to specify some LRECL value if you expect a long file.
You can also create a fixed-format file by using variations on the PUT statement, e.g.,
DATA _NULL_;
SET WORK.STUFF;
FILE "MY DOCUMENTS\TEXT_STUFF.TXT" LRECL=999;
PUT @1 ID
@10 ADDRESS
@50 PHONE;
RUN;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.