BookmarkSubscribeRSS Feed
cjinsf
Obsidian | Level 7

Hi!  Need a little help with an unix x command and its exit code in a macro.

The command is:

x "curl -k &loc. > /var/sas/projects/analyses/data_temp.txt";

Occasionally the web address in &loc. will just 'hang'- nothing happens and the SAS program doesn't continue (I know it's a valid address).

I was thinking something like

x "timeout 2s curl -k &loc. > /var/sas/projects/analyses/data_temp.txt";

might work- if the command times out there is a non-zero exit code so doing something like "retry until exit code = 0" might work (because the macro loops through and populates &loc. with different web addresses I don't want to lose the current value of &loc.; I know the problem is isn't the value of &loc. b/c there is success during subsequent sessions and a different previously successful web address may get stuck...).

How do I get the exit code?  Is it sysrc?  What would be the best way to keep trying the current &loc. until there is success?

(This macro previously ran with no problems; being able to re-try the current &loc. and see if it gets stuck again will help figure out why a problem has recently arisen).

Thanks for any help!

3 REPLIES 3
jakarman
Barite | Level 11

I would look at Piping. SAS(R) 9.4 Companion for UNIX Environments

It eliminates the temp.txt file as possible cause for hang-up. Watch the locking notes.

As curl is a Unix command to transfers docs Why using that when SAS has also those interfaces (FTP SFTP URL)?

SAS(R) 9.4 Statements: Reference (sftp) When this is sufficient it wil give you more control in all options.

Do you want to use curl Unix steps think about running the logical flow system with a professional scheduler like LSF 

It will solve timings delay-s hangups etc as monitoring on process-flow proceeding is one of the goals. 

---->-- ja karman --<-----
Tom
Super User Tom
Super User

I find that the SAS log is much clearer if you avoid the X or SYSEXEC command and instead use a PIPE within a DATA _NULL_ so that you can capture any messages that the program you are calling was trying to send to the terminal.  You probably also need to watch for special characters in your URL that might confuse SAS or your operating system's shell.  The QUOTE() function is useful if the macro variable includes double quote characters.

%let loc=http://mysite.com ;

data _null_;

   infile %sysfunc(quote(curl -k &loc. > /var/sas/projects/analyses/data_temp.txt)) pipe ;

   input ;

   put _infile_;

run;

cjinsf
Obsidian | Level 7

Thanks!  Had to use curl b/c of SSL error (used to use URL but certificates expired).  Being able to see the output to terminal in the log helps as well.

I appreciate your time!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 3 replies
  • 2286 views
  • 0 likes
  • 3 in conversation