Help using Base SAS procedures

Reg:Text Files importing at once from a folder to SAS Datasets.

Reply
Contributor
Posts: 66

Reg:Text Files importing at once from a folder to SAS Datasets.

Hi
I am having 40 text files in a folder with all same variables now i want to create all Text files to sas datasets with the name of the Text file names,how can i do for all them at once the text files are of differnt names a1,mmk,gds,9678c,kl89. As again the text files will be dumped day by day as the no will increse to 5000 how can i do for this.
Regular Contributor
Posts: 151

Re: Reg:Text Files importing at once from a folder to SAS Datasets.

You want as many SAS datasets as you have text files?
Do I understand you correctly?

Then try this code. Just change the input block according to your data.

[pre]

%let cfindir=d:\mbm\2010\m01\input; /* your input directory with text files*/
libname out v9 'd:\work'; /* your library for output datasets */


%macro cfin;
%let dlm=\;
%let filrf=mydir;
%let rc=%sysfunc(filename(filrf,"&cfindir"));
%let did=%sysfunc(dopen(&filrf));
%let lstname=;
%let memcount=%sysfunc(dnum(&did));
%if &memcount > 0 %then %do;
%do i=1 %to &memcount;
%let lstname=%sysfunc(dread(&did,&i));
%let file=&cfindir&dlm&lstname;
%let ln1=%index(&lstname,.);
%let ln1=%eval(&ln1-1);
%let ln2=%substr(&lstname,1,&ln1);
data out.&ln2 ;
infile "&file" firstobs=3 dlm=';' ls=32000 truncover dsd;
informat account $20. ss_naim $100. var1-var5 $1. ss_ostd 17. ss_ostc 17. ost_ccy 17. country $50. iso $3. client $100.
k_client $12. client_t $1. inn $char12. reg $char30. isin $char20. cb $char30.;
input account ss_naim var1-var5 ss_ostd ss_ostc ost_ccy country iso client
k_client client_t inn reg isin cb ;
run;
%end;
%let rc=%sysfunc(dclose(&did));
%end;
%mend cfin;

%cfin;


[/pre]
Contributor
Posts: 66

Re: Reg:Text Files importing at once from a folder to SAS Datasets.

First Thanks to OLeg_1976 for giving me good answer it has resolved 50% of my query


But i have some more to do.

In this folder daily new text file is joining and i want to create this to a dataset and append all the datasets to Final dataset. AS new Text file comes it should be created and Append to the Final Dataset .

2 Que: How can i know that the New Dataset was Created as New Text file came and how can i know the name of that particular dataset name?

Thanks
Regular Contributor
Posts: 151

Re: Reg:Text Files importing at once from a folder to SAS Datasets.

The possible solution is to check date and time of creation of the text files and then read these files to SAS dataset.

The code below is reading file attributes (date and time) to sas dataset.

[pre]
%let input=d:\dep\input\2010;
%let dir=%str(%'dir %")&input.%str(\%" /A-D/-C/ON/TW/4 %');


filename myfiles pipe %unquote(&dir);
data list1 (compress=no);
infile myfiles truncover ;
informat date ddmmyy10. time1 $5. bytes 8. name $100. ;
input date ?? @1 @; if not missing(date) then do;
input time1 13-17 bytes 19-35 name @37;
end; else delete;
time=input(time1,time5.);
format date ddmmyy10. time hhmm.; drop time1;
run;
filename myfiles clear;

[/pre]
Ask a Question
Discussion stats
  • 3 replies
  • 183 views
  • 0 likes
  • 2 in conversation