Hello all!
Hopefully someone can help me debug this program.
Right below is the starting mock table that outlines the problem...
(The tables don't render properly)
Patient_Number Day1 Day2 Day 3
123 A B A
124 A B C
The letters represent codes that have to be converted into their own variables and then summed so that what you have is:
Patient_Number Day1 Day2 Day 3 A B C
123 A B A 2 1 0
124 A B C 1 1 1
The first part of the macro creates the list and then there is an indirect call to it.
The second part attempts to create an array for every code to accomplish the above. The codes are part of a dataset...
the macro almost works as it does pass each code through. Except I am running into a hitch at the last moment. The problem is coming down to an improper "when" and/or improper do blocks somewhere.
The code and then part of the log follows below. Any assistance would be greatly appreciated!
THIS PART WORKS!
%macro split (data=, var=);
proc sort data=&data(keep=&var) out=values nodupkey;
by &var;
run;
data _null_;
set values end=last;
call symputx('site'||left(_n_),&var);
if last then call symputx('count',_n_);
run;
THIS PART DOES NOT!
DATA ALLDATA;
MERGE PTS INPUTDATA;
BY MR_;
select(&var);
%do i=1 %to &count;
when("&&site&i") %do;
array Cod&&site&i [7] Day1-Day7;
Code&&site&i=0;
DO I=1 to 7;
If Cod&&site&i="&&site&i" then Code&&site&i=Code&&site&i+1;
end;
%END;
%END;
drop I;
run;
%mend split;
%split(data=Codes, var=code)
Program Log:
DATA ALLDATA;
MPRINT(SPLIT): MERGE PTS INPUTDATA;
MPRINT(SPLIT): BY MR_;
MPRINT(SPLIT): select(code);
NOTE: Line generated by the invoked macro "SPLIT".
5 array Cod&&site&i [7] Day1-Day7; Code&&site&i=0; DO I=1 to 7; If
-----
180
5 ! Cod&&site&i="&&site&i" then Code&&site&i=Code&&site&i+1; end;
MPRINT(SPLIT): when("A") array CodA [7] Day1-Day7;
MPRINT(SPLIT): CodeA=0;
ERROR: Expecting "WHEN", "OTHERWISE", or "END".
MPRINT(SPLIT): DO I=1 to 7;
MPRINT(SPLIT): If CodA="A" then CodeA=CodeA+1;
MPRINT(SPLIT): end;