BookmarkSubscribeRSS Feed
sas_
Fluorite | Level 6
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.
3 REPLIES 3
Oleg_L
Obsidian | Level 7
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]
sas_
Fluorite | Level 6
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
Oleg_L
Obsidian | Level 7
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]

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 790 views
  • 0 likes
  • 2 in conversation