Problem with the INFILE Statement - Append data

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 14
Accepted Solution

Problem with the INFILE Statement - Append data

Hi everyone,

 

i have the following code:

 

%let mfileref=temp;
filename &mfileref 'PATH';

DATA x;

 did=dopen("&mfileref"); 
 memberCount = dnum( did );

DO j = 1 to memberCount; 
 fileName = dread( did, j ); 

 pathname= pathname("&mfileref");
 flow= filename; 
 path_flow=trim(pathname)!!'/'!!filename;

INFILE dummyf FILEVAR=path_flow FILENAME=myinfile DLM='09'x MISSOVER DSD lrecl=32767 firstobs=2 obs=5;

INFORMAT state $10.;
INFORMAT address $10.;
INFORMAT mail $10.;

FORMAT state $10.;
FORMAT address $10.;
FORMAT mail $10.;

INPUT 
 State
 Address
 Mail;

output;
END;
did = close(did);
STOP;


RUN;

The PATH character it's the directory from three txt files. Each txt file contains 50 records (for this example), i need create a data with 150 records (50+50+50). The code above just output 3 records, one of each txt file, my goal it's append all records from the three txt files on one file output. Please, help me!!! =D

 

Note: the example throws five records from the second row only. 


Accepted Solutions
Solution
‎05-16-2016 08:50 AM
Super User
Posts: 11,128

Re: Problem with the INFILE Statement - Append data

Remove

 did=dopen("&mfileref"); 
 memberCount = dnum( did );

DO j = 1 to memberCount; 
 fileName = dread( did, j ); 

 pathname= pathname("&mfileref");
 flow= filename; 
 path_flow=trim(pathname)!!'/'!!filename;

and the end statement.

Note, and this issue would have been in your original approach, that if you have header rows in those sets they will be read as data.

 

 

You can use combinations of stuff in the FILENAME statement

Filename dummy 'path/name*.txt path/bills*.txt'; would use all of the files in that folder starting with Name or Bills and ending in text.

 

Also when discussing an error generated by code on this site it is recommended to post the actual code and the entire error message from your log.

View solution in original post


All Replies
Super User
Posts: 11,128

Re: Problem with the INFILE Statement - Append data

If you only have 3 files  in the folder then using

filename dummy 'path/*.txt';

might be easier as that will have all of the files ending in txt in the filename, or if there is common name that a wildcard could use

 

filename dummy 'path/CommonPartOfFile_*.txt';

 

but your only getting 3 records because that is what you told it to read with your Do J = loop.

Occasional Contributor
Posts: 14

Re: Problem with the INFILE Statement - Append data

This example is for 3 files, in the future would be more. I tried with you suggestion but the program gave an error! How could i do? Do i remove the DO loop statement?
Solution
‎05-16-2016 08:50 AM
Super User
Posts: 11,128

Re: Problem with the INFILE Statement - Append data

Remove

 did=dopen("&mfileref"); 
 memberCount = dnum( did );

DO j = 1 to memberCount; 
 fileName = dread( did, j ); 

 pathname= pathname("&mfileref");
 flow= filename; 
 path_flow=trim(pathname)!!'/'!!filename;

and the end statement.

Note, and this issue would have been in your original approach, that if you have header rows in those sets they will be read as data.

 

 

You can use combinations of stuff in the FILENAME statement

Filename dummy 'path/name*.txt path/bills*.txt'; would use all of the files in that folder starting with Name or Bills and ending in text.

 

Also when discussing an error generated by code on this site it is recommended to post the actual code and the entire error message from your log.

Occasional Contributor
Posts: 14

Re: Problem with the INFILE Statement - Append data

[ Edited ]

WOOOW dude!! Thank you very much!! hahaha

 

I could merge the three files in one data step!! 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 326 views
  • 0 likes
  • 2 in conversation