Columns valorization in SAS

SAS know a lot about dummy variables.

data have;
   infile cards expandtabs;
   input id:$3. flag:$1.;
   cards;
012 A
345 B
678 C
;;;;
proc print;
proc transreg data=have design;
   model class(flag / zero=none);
   output out=coded;
   run;
proc print;
   run;

From your example there's no requirement for Table 1 to be used that I can see. If there is a need, you'll need to modify your example to show how it's relevant.

Otherwise, a quick and dirty way:

  • Use PROC FREQ to generate the counts and set them as 1 and 0s
  • Transpose to desired data structure
  • If you just need displayed output, the PROC FREQ step is enough
proc freq data=have ;
table id*flag / sparse out=long nopercent norow nocol;
run;


proc transpose data=long out=want (drop = _:);
by id;
id flag;
var count;
run;