trying to debug a macro

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 84
Accepted Solution

trying to debug a macro

I found some code and was trying to figure it out and debug it

in the macro it iterates through a web site grabbing the next page as it goes.

what i want to do is out put the contents of the record variable and or debug the code and examine what is in that variable ...is that possible?

%macro GetTrials(startlink=, out=Trials);

%let Continue=Yes;

%let NextLink=&startlink.;

%let i=0;

%do %while(&Continue.=Yes);

filename Trials url 'http://www.clinicaltrial.gov/%superq(NextLink)' lrecl=8192 debug;

data _Trials_(drop=recordline record nextpage);

length Status $25 Study $200 link $200;

retain Rank Status Study link;

retain recordLine 0; *=1 means this line may contain needed information;

infile Trials length=len;

input record $varying8192. len;

if find(upcase(record),"NEXT PAGE") then do;

if find(upcase(record),"HREF") then do;

  nextpage=htmldecode(prxchange('s/^.*?href="(.*?)".*?$/$1/i',-1,record));

  call symput("nextlink",nextpage);

end;

else call symput("Continue","No");

end;

run;

filename Trials clear;

data _Trials_;

set _Trials_ end=last;

if (last~=1) then output;

run;

proc append base=&out. data=_trials_;

run;

%let i=%eval(&i.+1);

%end;

%mend GetTrials;

%GetTrials(startlink=%str(ct2/results?state1=NA:CA:AB),out=AB_Trials);


Accepted Solutions
Solution
‎08-22-2014 06:54 PM
Super User
Super User
Posts: 7,039

Re: trying to debug a macro

Sounds like you are having trouble with the URL.  There is a DEBUG option you can add to the FILENAME statement.

I would debug that using a data step rather than attempting to debug the macro.

View solution in original post


All Replies
Super User
Super User
Posts: 7,039

Re: trying to debug a macro

Not sure I understand.  It looks to me like it is saving the RECORD variable into the dataset (s) that it generates.

If you want to see the value just print the data set.

Frequent Contributor
Posts: 84

Re: trying to debug a macro

I keep getting a blank datasset I was trying to see what each webpage looked like as I go through the itteration ...is that possible?

I was also getting an error

ERROR: Bad request. Use the debug option for more info.

but I couldnt figure out where it was coming from

Solution
‎08-22-2014 06:54 PM
Super User
Super User
Posts: 7,039

Re: trying to debug a macro

Sounds like you are having trouble with the URL.  There is a DEBUG option you can add to the FILENAME statement.

I would debug that using a data step rather than attempting to debug the macro.

Super User
Posts: 5,500

Re: trying to debug a macro

You could perform a quick and dirty examination by adding something along these lines after the INPUT statement:

if _n_ < 50 then put record $100.;

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 316 views
  • 0 likes
  • 3 in conversation