3

I have this simple PROC HTTP procedure inside a macro function.

I want the &trainname and the &date not to be resolved. But the &datum and the &treinnumer must be resolved.

I tried experimenting with the %nrstr and %str macro-functions, but nothing works.

 %macro treinnummers(treinnummer,datum);
        filename uit "/home/myfolder/sasuser.v94/test.html";    
        proc http url="http://www.belgianrail.be/jpm/sncb-nmbs-routeplanner/trainsearch.exe/nox?ld=abcde%nrstr(&trainname)=&treinnummer.%nrstr(&date)=&datum."out=uit; 
        run; 
 %mend;
Allan Bowe
  • 12,306
  • 19
  • 75
  • 124
Tom Dw
  • 53
  • 5

2 Answers2

2

There are many ways! One way which I have found to be reliable is to create your URL using data step then call via %superq() as follows:

%macro treinnummers(treinnummer,datum);
  filename uit "/home/myfolder/sasuser.v94/test.html"; 
  data _null_;
    format html $2048.;
    html=cats("http://www.belgianrail.be"
      ,"/jpm/sncb-nmbs-routeplanner/trainsearch.exe/nox?"
      ,'ld=abcde'
      ,'&trainname=',"&treinnummer"
      ,'&date=',"&datum");
    call symputx('html',html,'l');
  run;
  proc http url="%superq(html)" out=uit; run;
%mend;

Note the 'trick' above is to put macro variables in single quotes to prevent resolution. See here for more explanation..

Community
  • 1
  • 1
Allan Bowe
  • 12,306
  • 19
  • 75
  • 124
  • Thanks for your answer. Still getting the same error message: – Tom Dw Oct 21 '16 at 13:02
  • WARNING: Apparent symbolic reference TRAINNAME not resolved. WARNING: Apparent symbolic reference DATE not resolved. – Tom Dw Oct 21 '16 at 13:03
  • can you update your question to show exactly where in the log you are getting that message? Switching on `options mprint;` will help.. – Allan Bowe Oct 21 '16 at 20:07
0

I found the solution to my problem:

data _NULL_;
        format html $2048.;
        html=cats("http://www.belgianrail.be"
          ,"/jpm/sncb-nmbs-routeplanner/trainsearch.exe/nox?"
          ,'ld=abcde'
          ,'&trainname=',"&treinnummer"
          ,'&date=',"&datum");

        call symputx('html',html,'G');
run;

proc http url=%NRSTR("&html.") out=uit; run;
Tom Dw
  • 53
  • 5
  • yeah, I've had strange macro resolution issues using proc http also, hence the use of `%superq()` (taken from some working code of mine). Glad you figured it out.. – Allan Bowe Oct 27 '16 at 17:31