Creating Extensive Shift Tables OR How I Learned to Type 1,388,571 wpm! Kelley Weston The goal: Create a format that would consist of all the possible combinations of several values. For example: "M1TM" - "M1TM" = "Missing to 1+ to Trace to Missing" The usual way of accomplishing this: Typing all the combinations into a format. When there are only 4 or 5 possible values in 2 positions, this is no problem. The problem: We are starting with 7 values, in each of 4 positions. This results in 7 * 7 * 7 * 7 = 2401 combinations. The problems include: time ensuring that all possible combinations are accounted for, with no repetitions or omissions accuracy What I need to create: value $CAT_ALL "----" "---1" "---2" "---M" "---N" "---O" "---T" "--1-" "--11" "--12" "--1M" "--1N" "--1O" "--1T" "--2-" "--21" "--22" "--2M" "--2N" "--2O" "--2T" "--M-" "--M1" "--M2" "--MM" "--MN" "--MO" "--MT" "--N-" "--N1" "--N2" "--NM" (default = 40 fuzz = 0 min = 1 max = 40 ) - "----" = “missing" - "---1" = "to 1+" - "---2" = "to 2+" - "---M" = "to Missing" - "---N" = "to None" - "---O" = "to Other" - "---T" = "to Trace" - "--1-" = "- to 1+" - "--11" = "- to 1+ to 1+" - "--12" = "- to 1+ to 2+" - "--1M" = "- to 1+ to Missing" - "--1N" = "- to 1+ to None" - "--1O" = "- to 1+ to Other" - "--1T" = "- to 1+ to Trace" - "--2-" = "- to 2+" - "--21" = "- to 2+ to 1+" - "--22" = "- to 2+ to 2+" - "--2M" = "- to 2+ to Missing" - "--2N" = "- to 2+ to None" - "--2O" = "- to 2+ to Other" - "--2T" = "- to 2+ to Trace" - "--M-" = "- to Missing" - "--M1" = "- to Missing to 1+" - "--M2" = "- to Missing to 2+" - "--MM" = "- to Missing to Missing" - "--MN" = "- to Missing to None" - "--MO" = "- to Missing to Other" - "--MT" = "- to Missing to Trace" - "--N-" = "- to None" - "--N1" = "- to None to 1+" - "--N2" = "- to None to 2+" - "--NM" = "- to None to Missing" The solution: Lots of Pepsi ®! The Real Solution: Let SAS® create the combinations AND the meanings for them. The method: 1. 2. 3. 4. 5. Create a data set with the individual values and meanings. This will only consist of a very few records. In our case, we had 7 values. Let SAS create all the combinations and put them into a data set. We will cross the dataset with itself 3 times to create the 4 positions. Remember the Cartesian product? Post-process the dataset to account for baseline and missing values. Create the datasets from which we will create the permanent formats. Write out the permanent formats. Step 1 step 2a step 2b step 2c step 3 step 4a step 4b step 5 Step 1 data work.temp; length x $1 y $7; x = 'T'; y = x = '1'; y = x = '2'; y = x = 'O'; y = x = 'M'; y = x = '-'; y = x = 'N'; y = run; 'Trace'; '1+'; '2+'; 'Other'; 'Missing'; '-'; 'None'; output; output; output; output; output; output; output; outline Step 2a proc sql; create table work.temp as select x, y from work.temp order by x; outline Step 2b create table work.temp2 as select (a.x !! b.x) as x, (a.y !! ' to ' !! b.y) as y from work.temp as a, work.temp as b; outline Step 2c create table work.temp3 as select (a.x !! b.x) as x length = 200, compbl(a.y !! ' to ' !! b.y) as y length = 200 from work.temp2 as a, work.temp2 as b; outline Step 3 data work.temp3 (drop = to_); set work.temp3; %* format these especially for baseline records; if substr(x, 2) EQ '---' then y = scan(y, 1) !! " at baseline"; %* eliminate "to -"; do while (index(y, "to -") GT 0); to_ = index(y, "to -") ; y = left(trim(substr(y, 1, (to_ - 1)) !! substr(y, (to_ + 4)))); end; y = compbl(y); run; outline Step 4a data work.ctrl; length x y $200; length fmtname end $200; set work.temp end = last; retain fmtname 'cat' type 'c'; rename x = start y = label; end = x; run; outline Step 4b data work.ctrl2; length x y $200; length fmtname end $200; set work.temp3 end = last; retain fmtname 'cat_all' type 'c'; rename x = start y = label; end = x; run; outline Step 5 proc format library = library cntlin = work.ctrl; run; proc format library = library cntlin = work.ctrl2; run; outline Conclusion And that’s how I learned to type 1,388,571 wpm ! And boy, am I tired !