DATA Step, Macro, Functions and more

for help

Posts: 0

for help

I am trying to run the code following, but it keeps running infinitely. Can somebody figure out what is wrong with it, please? Thanks

libname learn 'F:\SPH project\alcohol task';
options mprint mlogic;

%macro etoh_category(type);
data socialhis_&type(drop=i);
set learn.socialhis;
length etoh $ 10;
%let i=%eval(1);
%do %while ("%scan(%nrbquote(&&&type),&i,'*')" ne ' ');
if index(compress(upcase(social_history)),trim("%scan(%nrbquote(&&&type),&i,'*')")) then etoh="&type";
%let i=%eval(&i+1);

Occasional Contributor
Posts: 8

Re: for help

If it is running infinitely and not ever stopping that means that the right side of this statement:

%do %while ("%scan(%nrbquote(&&&type),&i,'*')" ne ' ');

is never being met ... the NE ' '. Not having seen your data, whatever &&&type resolves to be is not ever returning an actual value. I think the reason is that what is in the ( ) is not actually resolving due to the double quotes around the %scan() function. So it is seeing the text "%scan(%nrbquote(&&&type),&i,'*')" as not equal to '' and never ending the loop.

Try removing the double quotes in both places and see if that makes a difference. If you need the value quoted, you can try adding:

%let myval = "%scan(%nrbquote(&&&type),&i,'*';

after the do while and then use "&myval" in your index() function instead of running the %scan again.

Super Contributor
Super Contributor
Posts: 3,174

Re: for help

The code, as shown, is generating a SAS warning:

WARNING: Apparent symbolic reference NONE not resolved

You need to define this macro variable for whatever purpose it has in your macro execution.

Scott Barry
SBBWorks, Inc.
Super Contributor
Posts: 359

Re: for help

Does &none have an assignment elsewhere? (as Scott pointed out &&&type resolves on first pass to &none then &none is not assigned) If not change:
%do %while ("%scan(%nrbquote(&&&type),&i,'*')" ne ' ');
to %do %while ("%scan(%nrbquote(&type),%eval(&i),'*')" ne "");

&i needs some help getting out and you had a space between single quotes which to a macro comparison is not the same as two double quotes without a space. This will stop the looping.

Now you will need to examine the rest of the macro since there are problems there as well.

A few more notes: try using symget(type) to bring the macro var into your data step. Also if type is a string which can be parsed on '*' as indicated it will not work as part of the dataset name.
Ask a Question
Discussion stats
  • 3 replies
  • 4 in conversation