Hello,
I am hoping there are some solutions to my problem. I have imported an ASCII file with over 500 variables into SAS using the Infile and Input statements as listed below:
Data WantImport;
Infile "File.txt" lrecl=4906 truncover;
Input
@1 Var1 Best4.
@5 Var2 $Char1.
@6 Var3 $Char35.
@41 Var4 $Char35.
@76 Var5 $Char20.
.....
run;
I then modified the file using a second database as a comparison file. Now I am wanting to export the ASCII file from SAS back into an ASCII file.
The proc export examples I have seen as shown below
proc export data=datawant
outfile="filename.txt"
dbms=dlm replace;
delimiter='';
putnames=no;
run;
does not account for the original ASCII format as referenced by the Input statement above. There are no delimiters just the variable name, length,type and other values written in the input statement.
Is there a special export statement for ASCII files?
Thank you in advance for your help.
Just use another DATA step to write the file. Instead of INFILE and INPUT you would use FILE and PUT.
data _null_;
set WantImport;
file "File.txt" ;
put
@1 Var1 Best4.
@5 Var2 $Char1.
@6 Var3 $Char35.
@41 Var4 $Char35.
@76 Var5 $Char20.
....
;
run;
Not being able to see the file, means its very difficult to say. In the read statement you do not say what the delimiter in that file is, so is the file not delimited, but actually uses fixed widths? Afraid its just guess work as we cannot see the file.
As to the final point, no there is nothing special to an ASCII file, all that means is its a text file, just like an rtf, or a csv or html or xml. There are numerous methods to writing data out to text files, again without seeing what is needed, I can't advise.
Thank you for responding. Yes the file uses fixed widths. Please see attached. I have attached the varialbe order, length and type for the 529 variables.
Please mark @Tom 's answer as the correct answer, not your response to him.
Just use another DATA step to write the file. Instead of INFILE and INPUT you would use FILE and PUT.
data _null_;
set WantImport;
file "File.txt" ;
put
@1 Var1 Best4.
@5 Var2 $Char1.
@6 Var3 $Char35.
@41 Var4 $Char35.
@76 Var5 $Char20.
....
;
run;
Thank you for the response! It worked. I appreciate it.
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.