BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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);
%end;
run;
%mend;

%etoh_category(none)
3 REPLIES 3
daveryBBW
Calcite | Level 5
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.

Daniel
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.
Flip
Fluorite | Level 6
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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 647 views
  • 0 likes
  • 4 in conversation