|
|
Re: Help: How to get this output (complicated case)
[code:sdq6rx49]data v;
input id $2. startdate $ stopdate $ day_of_week binary_value $ Type $ sum_working;
cards;
AA 01AUG08 31DEC08 2 101 monthly 200
BB 15SEP09 31DEC09 5 1010 monthly 250
;
run;
data v_o ;
set v;
/*set type*/
if binary_value ='101' then flag=0 ;
if binary_value ='1010' then flag=1;
/*Set month beginning date*/
startmonth=intnx('month',input(startdate,date7.),0);
stopmonth=intnx('month', input(stopdate,date7.),0);
do while (startmonth<=stopmonth);
/*get the first (second) in one month*/
if weekday(startmonth)^= day_of_week then;
do until(weekday(startmonth)=day_of_week);
startmonth+1;
end;
startmonth=startmonth+flag*7;
start= put(startmonth,date7.) ;
if startmonth>=input(startdate,date7.) and startmonth<= input(stopdate,date7.) then output;
/*get the third(forth) in one month*/
startmonth=intnx('day',startmonth,14);
start= put(startmonth,date7.) ;
if startmonth>=input(startdate,date7.) and startmonth<= input(stopdate,date7.)
and intck('month',startmonth-14,startmonth)=0 then output;
startmonth=intnx('month', startmonth,1);
end;
drop startmonth stopmonth flag;
run; [/code:sdq6rx49] |
|