05-11-2017 11:00 AM
I've Multiple text file in one location, I'm able to import them into one.
But Few files have 10 Variable/ few of them have 12 Variables/ Few of them are having 4 Variables.
The Variable which I wanted in final dataset present in all of them.
all of the text files have header and I want two of them.
Can I put those column name somewhere in below code ??
proc import datafile="Dir_Name/*.txt" out=work.Metadata dbms=dlm replace;
05-24-2017 05:29 AM
05-11-2017 11:33 AM
Well, I would only use proc import to generate the datastep for you. Once you have that code, update it by hand:
data want (keep=the_variable_you_want); infile "c:\temp\*.txt" dlm='09'x; input the_variable_you_want $ something_else ...; run;
If the other files don't contain all the varibles then you might get problems, hard to say without seeing the actual data. By similar are those columns completely missing? If so you would need either a program for each import, or you would read the whole of each file line by line and parse out the resulting strings.
05-15-2017 06:50 AM
05-15-2017 07:35 AM
You haven't said what "is not working". It will read in the data per the way you have coded it, if its not reading in the data correctly you need to code it per the data??
05-15-2017 07:54 AM
If you only want to keep some of the variables you can add the KEEP= dataset option to the output dataset name.
proc import datafile="Dir_Name/*.txt" dbms=dlm out=Metadata(keep=var1 var2 var3) replace ; delimiter='09'x; getnames=yes; guessingrows=max; quit;
Note that it is probably better to NOT use PROC IMPORT to guess at what is in your data files. Especially if you are going to combine multiple files. The only metadata on your variables that a delimited file contains are the column headers. Otherwise PROC IMPORT has to guess at how to define your variables. So if one file only has short names then it make make the name field too short. Or worse it might define as a number a field that should be character.
05-15-2017 08:05 AM
05-24-2017 05:29 AM
Need further help from the community? Please ask a new question.