0
proc sql noprint;  
    select count(distinct USUBJID) into : N1 - : N4 from DM where upcase(ARM) ^= "SCREEN FAILURE"`   
    group by ARMN;  
quit; 

%macro TOTAL(name=,num=);   
    %do i=1 %to #`    
    %if ARMN=&i %then TOTAL= put(COUNT,3.)||" (" ||right(put(COUNT*100/&&name&num,5.1))||"%) ";  
%end;    
%mend TOTAL;    

data TOTAL;    
    set DS;     
    %TOTAL(name=T,num=4);   
   /*if ARMN=1 then TOTAL= put(COUNT,3.)||" (" ||right(put(COUNT*100/&N1,5.1))||"%) ";*/    
run;

The above code is to assign number of subjects in treatment groups to macro variables and using the same to calculate the percentage as shown in the above code. The macro block written is not getting resolved in the datastep TOTAL and is not throwing a warning or an error.

Nimit_ZZ
  • 495
  • 4
  • 10
  • 21
  • Looks like the problem is with this statement in your macro definition: %if ARMN=&i %then... Macro statements compile before the open code does, so when %TOTAL compiles it knows nothing about your variable ARMN that will occur in the data step. – Dmitry Shopin Dec 14 '13 at 19:30
  • @DmitryShopin you should make your comment an answer, I think this is the core problem. – Jay Corbett Dec 15 '13 at 21:24
  • It should be a datastep 'if', not a macro %IF. `if ARMN=&i then TOTAL=` – Chris J Dec 16 '13 at 11:14

1 Answers1

2

I think your highest level problem is what @DmitryShopin mentions in his comment. However, my answer may be what is stopping the macro from resolving.

Your %If %Then statement within the %Total macro needs another semi-colon at the end. One semi-colon for the variable assignment statement and one semi-colon for the %If %Then statement. If you are generating more than one variable assignment statement, each one needs an ending semi-colon.

Not sure if this is the only problem without having sample data to test it.

Jay Corbett
  • 28,091
  • 21
  • 57
  • 74