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;
delimiter='09'x;
getnames=yes;
guessingrows=max;
quit;
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.
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??
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.
As I mention above, you need to code for your data. There is no magic wand to do your job.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.