Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

i have multiple .csv files in a unix directory.
every file is having variable names as header.even for empty file also.

suppose take 3 files
a.csv
b.csv
c.csv

a.csv contains data as
name;age,salary;
raja;34;4000;
ravi;33;5000;
kumar;25;3000;

b.csv contains data as
name;age,salary;
ajay;40;4500;


and c.csv contains
name;age,salary; (only headers)

Now i want to import and append all these files in to a single dataset.

i tried infile statement with *.csv to import all at a time.

but i m not getting correct data.
please help me . its urgent.
thank you in advance

Answer Posted / vrana95

/*So for this, you have to create a macro to store the path of the folder where your files are located .*/

/*STEP 1:*/

%let dirname = C:UsersRANAJIDesktopSAS_Class_CodeMultiple_csv_files;
filename DIRLIST pipe "dir /B &dirname*.csv";

data dirlist ;
length fname $256;
infile dirlist length=reclen;
input fname $varying256. reclen ;
run;
proc print data = dirlist;
run;

/* so , once your all files are located there, you can proceed with step 2 */

/* Step2*/

data all_text (drop=fname);
length myfilename $100;
length name $25;
set dirlist;
filepath = "&dirname"||fname;
infile dummy filevar = filepath length=reclen end=done missover;
do while(not done);
myfilename = filepath;
input name $ x1 x2 x3;
output;
end;
run;
proc print data=all_text;
run;

you will have all the files appended in the new dataset.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How do you control the number of observations and/or variables read or written?

1245


Name few SAS functions?

1091


What are the data types that sas contain?

1170


how does sas handle missing values in: assignment statements, functions, a merge, an update, sort order, formats, procs? : Sas programming

1023


what are the best practices to process the large data sets in sas programming? : Sas-administrator

1011


What is the basic syntax of a sas program?

1189


What do you know about sas and what we do? : sas-grid-administration

1135


This entry was posted in General. Bookmark the permalink. Post a comment or leave

4571


Describe what are the different levels of administrative users in sas? : sas-grid-administration

1030


How to read an input file in sas?

1136


Explain how merging helps to combine data sets.

1046


What are the prime responsibilities of data integration administrator? : Sas-di

1060


Name any two sas spawners? : sas-grid-administration

1035


Tell e how how dealt with..

2218


What makes sas stand out to be the best over other data analytics tools?

1053