09-30-2011 09:11 AM
Quite new to the macro world so here it goes,
I have a significant amount of txt files that i wish to upload into sas and then merge them . example of name of the files is as following:
zomb_201003.txt and etc.
They all contain the same info, so i was wondering is there any simple macro i could apply for this situation?
Thnx in advance
09-30-2011 09:17 AM
If by "merge" you mean concatenate (i.e., create one file that includes the records from all of the other files) then you may only need something as simple as:
input yourvariable_list ;
09-30-2011 09:29 AM
Yes concatenate it is sorry, one last question, what if i not sure how many variables are contained in each txt file and i have no headers, how could i face that?
09-30-2011 09:42 AM
SAS has no way of guessing what your files contain. For that, you either have to be able to recognize what the data represent or ask the person who created the file(s). You could always bring one of the files up in a text editor (like notepad or wordpad) and see if you can recognize the key parameters, e.g., how many fields, how are they separated, are character fields enclosed in quotes, what each field represents, etc.).
Then, you can use proc import to import one of the files and, after it has done so, press F3 to get SAS to spit back the actual code it wrote to import the file.
From there, you should be well on your way to answering your own question.
09-30-2011 10:25 AM
thank for clearing that up, i have tried the following
since i found some dataset with var names
input AcNum Sum D ;
but it doesnt seem to capture the data containted in the files , any last guess or maybe i miss understood something from the above mentioned
09-30-2011 10:33 AM
It would help if you could post one of the files or at least the first 10 records or so, as well as the messages you received in your log. Like I mentioned, I would try to import one of the files using proc import and then seeing what code it wrote. Chances are that you will have to include some informat and format lines so that SAS knows what kind of data it is reading. But, even then, you would have to tell SAS what kind of file it is, i.e., delimited (and if so with what kind of delimiter).
You will also probably have to input the files in two groups, one that has a header record and one that doesn't, and specify on which row the data actually start in each set.
10-02-2011 05:20 AM
Just as Art said. For your situation , the best way is to use proc import, let SAS do it for you automatically.
But I recommend to use filename + pipe to get filename firstly ,then use macro to loop proc import .
10-03-2011 09:41 AM
You never did post a couple of records from each of your two types of files (i.e., those that do and those that do not have header records). It is quite possible to write code that can determine whether or not a header record exists and do all of the imports in one pass.