Close - the code is two macros, one to count the words in any macro variable separated by commas and a space. The result is just the number of words in the list, in the example it should be two. Your SAS log will show this. The second macro is %read_txtFiles. It will do just that. It will run twice for de and ri, or to the count of &wrd_cnt. parse the _states macro and read in each state file. The proc import can be changed to any metod to import the txt file. All you really need to change is the %let _states list with the list of states to read, originally 47. change the %let _dsn to simple state names, can be the same as _states. I have the options statement to show how the macro is resolving %macro _wordcntC(list); %global wrd_cnt; %let wrd_cnt=%sysfunc(countw(%nrquote(&list),%str(,))); %put "# of words in list are &wrd_cnt"; %mend _wordcntC; ****** keep what is above ****************; ****** my example of the state list *****************; %let _states="Illinois, NewYork, New Mexico, California"; ****** single sas dataset output from macro *********; %let _dsnlst=Illinois, New York, New Mexico, California; ***** call the macro _wordcntC to get the number of states in the %let _states list *****; ***** for your example this should be 2, make sure you have spaces between the states like below ***; %let _states="ri, de"; %let _dsnlst=ri, de; %_wordcntC(&_states); options mprint mlogic symbolgen; %macro read_txtFiles(states); %local state; *** ***; *** read each state in from the _states list macro variable ***; *** assign it to a new macro variable word ***; *** the proc import will import the file from the desktop ***; *** the result sas dsn will be appended to _allstates ***; %do j = 1 %to &wrd_cnt; %let word=%qscan(%nrquote(&states),&j,%str(,)); %let _dsn=%qscan(%nrquote(&_dsnlst),&j,%str(,)); PROC IMPORT OUT=&_dsn DATAFILE="C:\Documents and Settings\xyz\Desktop\&word..txt"; SCANTEXT=YES; USEDATE=YES; SCANTIME=YES; RUN; proc append base=_allstates data=&syslast force; run; proc datasets lib=WORK; delete &dsn; quit; filename _all_ clear; run; %end; %mend read_txtFiles; %read_txtFiles(&_states);
... View more