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

Hi,

 

I automated a program that processes a file.  The file is transferred to a directory (mydir) and is typically available by a certain time (noon lets say).  However, activity has grown, thus the file has grown, and has been late to arrive a few times recently.  I'm trying to code some handling to check if the file is available, and if it isnt, sleep and write a message to the log until it is available.  I'm having trouble getting the message to print to the log.  here's my program:

 

data _null_;
 isthere = 0;
 do until (isthere = 1);
  if fileexist("/mydir/myfile.txt") then isthere = 1;
  else x = sleep(60) and put 'file not available' ; 
end;

libname pdb0 "/mydir";

data temp0;
 set pdb0.myfile;
run;

proc print data = temp0 (obs = 10);
run;

Every time the program sleeps, i also want it to print 'file not available' to the log.

 

I've searched a bunch but can't seem to find a good solution.  Can someone please help?

 

Thank you,

Jon

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

To create a block of code use DO/END.

else do;
  put 'file not available' ; 
  x = sleep(60);
end;

View solution in original post

8 REPLIES 8
SASKiwi
PROC Star

The SAS PUT statement will write to the SAS log by default. There is also a PUTLOG statement that will write explicitly to the SAS log if you have other PUT statements writing elsewhere.

 

BTW, if you want to trigger SAS processing based on the existence of a file then many schedulers have this capability and then you can avoid coding for this entirely.

prolifious
Obsidian | Level 7

thank you.  where should i code the put then?  thats the part im having trouble with.  i saw putlog and error, but i couldn't code it correctly. can you please provide an example, please?

SASKiwi
PROC Star
data _null_;
  putlog "This is a message in the SAS log";
run;
prolifious
Obsidian | Level 7

yes, thank you, but my question is - how do i incorporate that in the else of the do until?

 

esle0.PNG

 

 

 

 

Tom
Super User Tom
Super User

To create a block of code use DO/END.

else do;
  put 'file not available' ; 
  x = sleep(60);
end;
prolifious
Obsidian | Level 7

here is what ended up working:

 

else do;
  put 'file not available' ; 
  x = sleep(60,1);
end;

without the ,1 in the sleep, i don't beleive the program slept, its jsut kep going through the loop and continually prints 'not available', but now it works as i like.  Thanks so much!!

ballardw
Super User

I would strongly recommend putting some sort of counter inside that loop and if a period of time that you think is excessive passes without finding the file that you end the loop, write an appropriate message somewhere and terminate the job or some sort of "nice" exception handling.

 

prolifious
Obsidian | Level 7

i don't really care how many times it goes through, but i do care if it goes past a certain time mark, 1700 for instance.  I'll do that.  thanks again for all your help out there.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 8 replies
  • 596 views
  • 2 likes
  • 4 in conversation