Rewriting someone else's code is not that easy. Here is my try, admittedly a bit macro heavy. It may be possible (or better) if you convert these funtion-style macros into proper fcmp functions -- I didn't bother because they were just one-liners. /* test data */ data one; do trade_date_time = "21jun2011 01:00:00"dt to "23sep2011 23:00:00"dt by 60*60; output; end; run; /* proc format lookup approach -- macro heavy */ %*-- consts --*; %let start = %sysevalf("22jun2011"d); %let finish = %sysevalf("21sep2011"d); %let holidays = ("3jul2011"d, "4jul2011"d, "4sep2011"d, "5sep2011"d); %let firstdaysBack = ("05jul11"d, "06sep2011"d); %let friday = (6); %let saturday = (7); %*-- helpers --*; %macro dt(date, hour); put(dhms(&date,&hour,0,0), best12.) %mend dt; %macro lbl(); put(input(label, best.) + 1, best12.) %mend lbl; %macro out(start, end, hlo, label); do; start=&start; end=&end; hlo=&hlo; label=&label; output; end; %mend out; /* create a user-defined numeric informat */ data groups; retain fmtname "group" type "i"; length start end label $12 hlo $1; %out("", %dt(&start, 16), "L", "1") do date = &start to &finish; if date in &holidays then continue; if date in &firstDaysBack then %out(%dt(date, 00), %dt(date, 16), "", %lbl()) dow = weekday(date); if dow = &saturday then continue; hour = ifn(dow = &friday, 00, 16); %out(%dt(date, 17), %dt(date + 1, hour), "", %lbl()) end; %out("", "", "O", "0") run; proc format cntlin=groups; quit; /* create the group variable using the informat */ data chang; set one; group = input(put(trade_date_time,best.), group.); run; /* skipper^s wall-paper code */ data skipper; set one; if trade_date_time <= "22JUN11:16:00:00"dt then group=1; else if "22JUN11:17:00:00"dt <= trade_date_time <= "23JUN11:16:00:00"dt then group=2; else if "23JUN11:17:00:00"dt <= trade_date_time <= "24JUN11:16:00:00"dt then group=3; else if "24JUN11:17:00:00"dt <= trade_date_time <= "25JUN11:00:00:00"dt then group=4; else if "26JUN11:17:00:00"dt <= trade_date_time <= "27JUN11:16:00:00"dt then group=5; else if "27JUN11:17:00:00"dt <= trade_date_time <= "28JUN11:16:00:00"dt then group=6; else if "28JUN11:17:00:00"dt <= trade_date_time <= "29JUN11:16:00:00"dt then group=7; else if "29JUN11:17:00:00"dt <= trade_date_time <= "30JUN11:16:00:00"dt then group=8; else if "30JUN11:17:00:00"dt <= trade_date_time <= "01JUL11:16:00:00"dt then group=9; else if "01JUL11:17:00:00"dt <= trade_date_time <= "02JUL11:00:00:00"dt then group=10; else if "05JUL11:00:00:00"dt <= trade_date_time <= "05JUL11:16:00:00"dt then group=11; else if "05JUL11:17:00:00"dt <= trade_date_time <= "06JUL11:16:00:00"dt then group=12; else if "06JUL11:17:00:00"dt <= trade_date_time <= "07JUL11:16:00:00"dt then group=13; else if "07JUL11:17:00:00"dt <= trade_date_time <= "08JUL11:16:00:00"dt then group=14; else if "08JUL11:17:00:00"dt <= trade_date_time <= "09JUL11:00:00:00"dt then group=15; else if "10JUL11:17:00:00"dt <= trade_date_time <= "11JUL11:16:00:00"dt then group=16; else if "11JUL11:17:00:00"dt <= trade_date_time <= "12JUL11:16:00:00"dt then group=17; else if "12JUL11:17:00:00"dt <= trade_date_time <= "13JUL11:16:00:00"dt then group=18; else if "13JUL11:17:00:00"dt <= trade_date_time <= "14JUL11:16:00:00"dt then group=19; else if "14JUL11:17:00:00"dt <= trade_date_time <= "15JUL11:16:00:00"dt then group=20; else if "15JUL11:17:00:00"dt <= trade_date_time <= "16JUL11:00:00:00"dt then group=21; else if "17JUL11:17:00:00"dt <= trade_date_time <= "18JUL11:16:00:00"dt then group=22; else if "18JUL11:17:00:00"dt <= trade_date_time <= "19JUL11:16:00:00"dt then group=23; else if "19JUL11:17:00:00"dt <= trade_date_time <= "20JUL11:16:00:00"dt then group=24; else if "20JUL11:17:00:00"dt <= trade_date_time <= "21JUL11:16:00:00"dt then group=25; else if "21JUL11:17:00:00"dt <= trade_date_time <= "22JUL11:16:00:00"dt then group=26; else if "22JUL11:17:00:00"dt <= trade_date_time <= "23JUL11:00:00:00"dt then group=27; else if "24JUL11:17:00:00"dt <= trade_date_time <= "25JUL11:16:00:00"dt then group=28; else if "25JUL11:17:00:00"dt <= trade_date_time <= "26JUL11:16:00:00"dt then group=29; else if "26JUL11:17:00:00"dt <= trade_date_time <= "27JUL11:16:00:00"dt then group=30; else if "27JUL11:17:00:00"dt <= trade_date_time <= "28JUL11:16:00:00"dt then group=31; else if "28JUL11:17:00:00"dt <= trade_date_time <= "29JUL11:16:00:00"dt then group=32; else if "29JUL11:17:00:00"dt <= trade_date_time <= "30JUL11:00:00:00"dt then group=33; else if "31JUL11:17:00:00"dt <= trade_date_time <= "01AUG11:16:00:00"dt then group=34; else if "01AUG11:17:00:00"dt <= trade_date_time <= "02AUG11:16:00:00"dt then group=35; else if "02AUG11:17:00:00"dt <= trade_date_time <= "03AUG11:16:00:00"dt then group=36; else if "03AUG11:17:00:00"dt <= trade_date_time <= "04AUG11:16:00:00"dt then group=37; else if "04AUG11:17:00:00"dt <= trade_date_time <= "05AUG11:16:00:00"dt then group=38; else if "05AUG11:17:00:00"dt <= trade_date_time <= "06AUG11:00:00:00"dt then group=39; else if "07AUG11:17:00:00"dt <= trade_date_time <= "08AUG11:16:00:00"dt then group=40; else if "08AUG11:17:00:00"dt <= trade_date_time <= "09AUG11:16:00:00"dt then group=41; else if "09AUG11:17:00:00"dt <= trade_date_time <= "10AUG11:16:00:00"dt then group=42; else if "10AUG11:17:00:00"dt <= trade_date_time <= "11AUG11:16:00:00"dt then group=43; else if "11AUG11:17:00:00"dt <= trade_date_time <= "12AUG11:16:00:00"dt then group=44; else if "12AUG11:17:00:00"dt <= trade_date_time <= "13AUG11:00:00:00"dt then group=45; else if "14AUG11:17:00:00"dt <= trade_date_time <= "15AUG11:16:00:00"dt then group=46; else if "15AUG11:17:00:00"dt <= trade_date_time <= "16AUG11:16:00:00"dt then group=47; else if "16AUG11:17:00:00"dt <= trade_date_time <= "17AUG11:16:00:00"dt then group=48; else if "17AUG11:17:00:00"dt <= trade_date_time <= "18AUG11:16:00:00"dt then group=49; else if "18AUG11:17:00:00"dt <= trade_date_time <= "19AUG11:16:00:00"dt then group=50; else if "19AUG11:17:00:00"dt <= trade_date_time <= "20AUG11:00:00:00"dt then group=51; else if "21AUG11:17:00:00"dt <= trade_date_time <= "22AUG11:16:00:00"dt then group=52; else if "22AUG11:17:00:00"dt <= trade_date_time <= "23AUG11:16:00:00"dt then group=53; else if "23AUG11:17:00:00"dt <= trade_date_time <= "24AUG11:16:00:00"dt then group=54; else if "24AUG11:17:00:00"dt <= trade_date_time <= "25AUG11:16:00:00"dt then group=55; else if "25AUG11:17:00:00"dt <= trade_date_time <= "26AUG11:16:00:00"dt then group=56; else if "26AUG11:17:00:00"dt <= trade_date_time <= "27AUG11:00:00:00"dt then group=57; else if "28AUG11:17:00:00"dt <= trade_date_time <= "29AUG11:16:00:00"dt then group=58; else if "29AUG11:17:00:00"dt <= trade_date_time <= "30AUG11:16:00:00"dt then group=59; else if "30AUG11:17:00:00"dt <= trade_date_time <= "31AUG11:16:00:00"dt then group=60; else if "31AUG11:17:00:00"dt <= trade_date_time <= "01SEP11:16:00:00"dt then group=61; else if "01SEP11:17:00:00"dt <= trade_date_time <= "02SEP11:16:00:00"dt then group=62; else if "02SEP11:17:00:00"dt <= trade_date_time <= "03SEP11:00:00:00"dt then group=63; else if "06SEP11:00:00:00"dt <= trade_date_time <= "06SEP11:16:00:00"dt then group=64; else if "06SEP11:17:00:00"dt <= trade_date_time <= "07SEP11:16:00:00"dt then group=65; else if "07SEP11:17:00:00"dt <= trade_date_time <= "08SEP11:16:00:00"dt then group=66; else if "08SEP11:17:00:00"dt <= trade_date_time <= "09SEP11:16:00:00"dt then group=67; else if "09SEP11:17:00:00"dt <= trade_date_time <= "10SEP11:00:00:00"dt then group=68; else if "11SEP11:17:00:00"dt <= trade_date_time <= "12SEP11:16:00:00"dt then group=69; else if "12SEP11:17:00:00"dt <= trade_date_time <= "13SEP11:16:00:00"dt then group=70; else if "13SEP11:17:00:00"dt <= trade_date_time <= "14SEP11:16:00:00"dt then group=71; else if "14SEP11:17:00:00"dt <= trade_date_time <= "15SEP11:16:00:00"dt then group=72; else if "15SEP11:17:00:00"dt <= trade_date_time <= "16SEP11:16:00:00"dt then group=73; else if "16SEP11:17:00:00"dt <= trade_date_time <= "17SEP11:00:00:00"dt then group=74; else if "18SEP11:17:00:00"dt <= trade_date_time <= "19SEP11:16:00:00"dt then group=75; else if "19SEP11:17:00:00"dt <= trade_date_time <= "20SEP11:16:00:00"dt then group=76; else if "20SEP11:17:00:00"dt <= trade_date_time <= "21SEP11:16:00:00"dt then group=77; else if "21SEP11:17:00:00"dt <= trade_date_time <= "22SEP11:16:00:00"dt then group=78; else group=0; run; /* check */ proc compare base=skipper compare=chang; run; /* on lst -- in part NOTE: No unequal values were found. All values compared are exactly equal. */
... View more