BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jimbobob
Quartz | Level 8

Hello all, in a previous question I needed help with a wire format import see: https://communities.sas.com/t5/SAS-Programming/fedwire-funds-format-files-with-tags-and-elements/td-...

 

This has been working fantastically, however, as the number of files grow, I would like to use a dataset that list the files in a specific directory, compare that to my data already processed and only process new files. I've been able to do this for other imported text and csv files. With this particular layout of data, I'm only able to get the first record to import and it doesn't import the other two records. I tried adding a end=done, and do while (not done) but it runs indefinitely, tried putting the do while in different locations, but I'm at a lost.

%macro wires(path); 
	filename pipedir pipe " dir ""&path\"" " lrecl=5000;
	data FILES_LISTED;
		infile pipedir truncover;
		input line $char1000.;
		length DIRECTORY $1000;
		retain DIRECTORY;
		if line =' ' or	index(upcase(line),'<DIR>') or left(upcase(line)) = :'VOLUME' then delete;
		if left(upcase(line)) = :'DIRECTORY OF' then DIRECTORY = left(substr(line,index(upcase(line),'DIRECTORY OF')+12));
		if left(upcase(line)) = :'DIRECTORY OF' then delete;
		if input(substr(line,1,10),?? mmddyy10.) = . then delete;
		FILE_DATE = input(substr(line,1,20),?? anydtdtm32.);
		format FILE_DATE NLDATMAP20.;
		FILE_SIZE = INPUT(substr(line,21,19),comma20.); 
		FILE_NAME = STRIP(substr(line,40));
		FILES = CATX("\",DIRECTORY,FILE_NAME);
		drop line;
		if index(upcase(FILE_NAME),'.ACK') or index(upcase(FILE_NAME),'.DAT') or index(upcase(FILE_NAME),'.XLSX') 
			or index(upcase(FILE_NAME),'.XLS') or index(upcase(FILE_NAME),'.PDF') or index(upcase(FILE_NAME),'.LNK') 
			or index(upcase(FILE_NAME),'.ZIP') or index(upcase(FILE_NAME),'.RPT') or index(upcase(FILE_NAME),'.CSV')
			or index(upcase(FILE_NAME),'.PRC643') or index(upcase(FILE_NAME),'.TSV') then delete;
	run;
	PROC SQL;
		CREATE TABLE WORK.NEW_FILES AS SELECT 
			t1.DIRECTORY, 
			t1.FILE_DATE, 
			t1.FILE_SIZE, 
			t1.FILE_NAME, 
			t1.FILES
		FROM WORK.FILES_LISTED t1
		WHERE FILE_NAME LIKE "%.txt";
	QUIT;
	data dsn;
		length row col tag 8 extra $32 text $1000;
		set NEW_FILES;
		location=cats("&path\",FILE_NAME);
		infile dummy filevar=location DLM="{}" truncover end=done;
		do while (not done);
			row+1;
			input tag ?? @1 @;
			if missing(tag) then input extra @ ;
			do col=1 by 1 until(tag=' ');
				input tag text @;
				if tag ne ' ' then output;
			end;
		end;
	run;
%mend wires;
%wires(C:\Users\jwalker\Desktop\DataFileInputs\Sablewires\New Folder)
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

You don't appear to ever read past the first line of the file because all of your INPUT statements have a trailing @.  And since you are running them all in a single iteration SAS never moves to the next line.

do while (not done);
  row+1;
  input tag ?? @1 @;
  if missing(tag) then input extra @ ;
  do col=1 by 1 until(tag=' ');
    input tag text @;
    if tag ne ' ' then output;
  end;
  input;
end;

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

You don't appear to ever read past the first line of the file because all of your INPUT statements have a trailing @.  And since you are running them all in a single iteration SAS never moves to the next line.

do while (not done);
  row+1;
  input tag ?? @1 @;
  if missing(tag) then input extra @ ;
  do col=1 by 1 until(tag=' ');
    input tag text @;
    if tag ne ' ' then output;
  end;
  input;
end;
jimbobob
Quartz | Level 8

Thanks Tom, so putting a Input; appears to stop the current hold of the @ and moves on to next record, if I'm understanding right. Appreciate it.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

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.

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
  • 2 replies
  • 434 views
  • 2 likes
  • 2 in conversation