title: sas collapsing categorical variables clustering analysis
body: <p>I came across the following code in the logistic regression modeling course offered by SAS:</p>
  
  <pre><code>data dataset(drop=i);
  set data;
  
  array mi{*} mi_Ag mi_Inc
  mi_WR;
  
  array x{*} Ag Inc WR;
  do i=1 to dim(mi);
  mi{i}=(x{i}=.);
  end;
  run;
  </code></pre>
  
  <p>I need to understand two things:</p>
  
  <p>1.) there is a column created titled "i" once this data step is run. What does that signify and why is there. The drop "i" essentially drops it but if i don't use drop option the column stays in the data set</p>
  
  <p>2.) this do step is replacing all the missing values with a 1 and rest with 0. How is that happening when nothing is clearly specified in the do step as to what needs to be done. In my eyes, "do i=1 to dim(mi); mi{i}=(x{i}=.);" should simply put dots in mi(i) wherever it finds dots in x(i).</p>
  
  <p>Part 2:</p>
  
  <p>While collapsing the categorical variable, following code has been used:</p>
  
  <pre><code>proc freq data=example1 noprint;
    tables CLUSTER_CODE*TARGET_B / chisq;
    output out=out_chi(keep=_pchi_) chisq;
  run;
  
  data ex_cutoff;
    if _n_=1 then set out_chi;
    set ex_cluster;
    chisquare=_pchi_*rsquared;
    degfree=numberofclusters-1;
    logpvalue=logsdf('CHISQ',chisquare,degfree);
  run;
  </code></pre>
  
  <p>what is <em>n</em>=1 doing ? and also, why are we creating chisquare=_pchi*rsquared. <em>pchi</em> is already chisquare so whats the point of multiplying it with R square?</p>
  
  <p>Thanks</p>
  
  <p>P.S. The code is from one of the SAS learning courses. Hopefully I am allowed to share it here for discussion/learning purposes.</p>