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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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;

View solution in original post

5 REPLIES 5
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

corsan
Calcite | Level 5

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.

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Please mark @Tom 's answer as the correct answer, not your response to him.

Tom
Super User Tom
Super User

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;
corsan
Calcite | Level 5

Thank you for the response! It worked. I appreciate it.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 5 replies
  • 5799 views
  • 0 likes
  • 3 in conversation