> [pre]
> options symbolgen;
> %let groupvalues="Lot_Id,Facility";
> %let nrGroupValues = %sysfunc(countw(&groupvalues,'
> '));
> %put &nrGroupValues;
>
>
> %macro test;
> %if "&groupvalues" ne ' ' %then %do;
> nrGroupValues = %sysfunc(countw(&groupvalues,','));
> %do %while(CounterVariable le nrGroupValues);
> GroupValue = scan(&groupvalues,CounterVariable,'
> ' ');
> %put &nrGroupValues;
> t CounterVariable;
> %put GroupValue;
> CounterVariable = CounterVariable + 1;
> %end;
> %end;
> %mend;
> %test;
>
> [/pre]
> what is wrong with this code?
> it crashes on multiple places
>
> Message was edited by: Filipvdr
I think the problem is that with the Variable CounterVariable, nrGroupValues and GroupValue. The variables are being referenced without '&' and are being initialized without %let.
It looks like you are using Datastep Variables and Functions (SCAN) within the macro that does not have a datastep at all.
Try this:
options nosymbolgen;
%let groupvalues="Lot_Id,Facility";
%let nrGroupValues = %sysfunc(countw(&groupvalues,' '));
%put nrGroupValues_1: &nrGroupValues;
%let CounterVariable=1;
%macro test;
%if &groupvalues ne ' ' %then %do;
%let nrGroupValues = %sysfunc(countw(&groupvalues,','));
%do %while(&CounterVariable le &nrGroupValues);
%let GroupValue = %scan(&groupvalues,&CounterVariable,' ');
%put nrGroupValues_2 : &nrGroupValues;
%put CounterVariable: &CounterVariable;
%put GroupValue: &GroupValue;
%let CounterVariable = %eval(&CounterVariable + 1);
%end;
%end;
%mend;
%test;
Log:
nrGroupValues_1: 1
nrGroupValues_2 : 2
CounterVariable: 1
GroupValue: "Lot_Id,Facility"
nrGroupValues_2 : 2
CounterVariable: 2
GroupValue:
This runs without any error. But I did not understand what you are trying to achieve.
Message was edited by: bhavani
Message was edited by: bhavani
Message was edited by: bhavani