Re: Read the file names and create a dataset

After applying your advise I slightly tweaked my code with macro, but again I end up with other error.

In this case, I've the file names in output_file.txt and I reading it to create a dataset. Please be informed I need to create a dataset only if file name (part of file name) matches. My management want me to develop with this code via macro and hence I used macro in my code.

Re: Read the file names and create a dataset

The error message is pretty clear. You cannot code INFILE 'myfile' FILEVAR=myfilenamevar ... since you are giving it the physical name in two places. Replace the quoted filename with a dummy fileref. INFILE dummy FILEVAR=myfilenamevar ... ;

My question, how SAS will recongnize that the file reference 'dummy' is the file names to be read from the dataset log.output_file. Please be informed that there is only the filename in the dataset log.output_file. There is no path in the dataset or anywhere in the program.

Kindly guide me where should I mention the path in the program which makes life easier. Just I need to know whether the file output_fil​e.txt should have the path along with file names or I should mention in infile statement which is under the macro.

I would request you to see my previous post to understand the files and other stuffs.

The fact that fname is present in the data step that creates code through call execute does in no way imply that the variable somehow magically appears in the generated code (which is executed AFTER the data step doing the call execute has ended). You have to provide for some mechanism to get the filenames into your main step.

And I feel you are thinking way too complicated here.

My immediate solution would look like this:

- create a data step to read one single log file into an intermediate file

- wrap that in a macro definition that accepts the input filename as a parameter, and has a second step appending the data to a base file

- call that macro in a data step that reads the input filenames; every iteration will add another log output to your base file-

Re: Read the file names and create a dataset

You are making it much too complicated. As someone said above the main error is that you cannot use a subsetting IF statement because that will break out of the DO WHILE loop and terminate the processing of the current file. You need to use IF/THEN/DO/END instead to conditionally execute the OUTPUT statement.

You probably should add some LENGTH or ATTRIB statements to define the variables that you are scanning from the lines in the log file. As the code is currently written they will all be character length 3000 since they are derived from string operations on VAR1 which is defaulting to the same because of the format used on the INPUT statement.