There are multiple files in my unix folder(csv,txt).I want to convert them all into sas datasets through SAS EG.
Could someone help with this please?
You can run PROC IMPORT on them, but be advised that this involves guessing and is therefore unreliable.
If the files share the same structure, you need to run the same data step on them to get identical (in terms of variable attributes) results.
Please be more specific. Are the datasets resulting from the import meant to be appended (same structure), or do they share common key columns which need to be used later on in joins, or are they completely independent and have no relationship at all?
A list of files in a folder is easily done, either by running the UNIX ls command in a FILENAME PIPE, or by using the FILENAME, DOPEN, DNUM and DREAD functions in a data step.
Search for "list files in directory" here on the communities, as this question has been asked and answered numerous times.
Use EG to help you write some SAS code to read the files.
Do you know what is in the files? If so just write a data step to read them.
If you don't know are you ok with SAS guessing how to define the variables? If so just use PROC IMPORT.
@sindhura1 wrote:
yes i am able to do proc import with single file.But unable to do with multiple files
Get the list of files:
data files;
input 'ls /myfolder/*.csv' pipe truncover;
input filename $256. ;
run;
Then generate code to convert each one. Here is a simple process, but you might need to make it more complicated if the base names of your files are not valid SAS member names (or not unique).
data _null_;
set files;
call execute(catx(' '
,'proc import datafile=',quote(trim(filename))
,'dbms=csv'
,'out=',scan(filename,-2,'/.'),'replace'
,';'
,'run;'
));
run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.