3
votes

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;
2

2 Answers

2
votes

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..

0
votes

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;