Sas calculation program doesn't run -
i have following data set:
date jobboardid sales jan05 3 256 jan05 6 70 jan05 54 90 feb05 32 456 feb05 11 89 feb05 16 876 march05 april05 . . . jan06 6 678 jan06 54 87 jan06 13 56 feb06 mcdonald 67 feb06 11 281 feb06 16 876 march06 april06 . . . jan07 6 567 jan07 54 76 jan07 34 87 feb07 10 678 feb07 11 765 feb07 16 67 march07 april06
i trying calculate 12 month growth rate sales column when jobboardid column has same value 12 months apart. have following code:
data want; set have; date jobboardid; format till monyy7.; = lag12(date); oldsales = lag12(sales); if lag12 (jobboardid) eq jobboardid , intck('month', from, date) eq 12 do; till = date; rate = (sales - oldsales) / oldsales; output; end; run;
however keep getting following error message: note: missing values created result of performing operation on missing values.
but when checked dataset, there aren't missing values. what's problem?
note: date column in monyy7. format. jobboardid numeric value , sales.
the note being thrown intck() function. when from=lag12(date)
first 12 records have missing value from. , intck('month', from, date)
throw note. though intck not used in assignment statement, still throws note because 1 of arguments has missing value. below example. log reports missing values created 12 times, because used lag12.
77 data have; 78 date=1 20; 79 output; 80 end; 81 run; note: data set work.have has 20 observations , 1 variables. 82 data want; 83 set have; 84 from=lag12(date); 85 if intck('month',from,today())=. put 'missing: ' (_n_ date)(=); 86 else put 'not missing: ' (_n_ date)(=); 87 run; missing: _n_=1 date=1 missing: _n_=2 date=2 missing: _n_=3 date=3 missing: _n_=4 date=4 missing: _n_=5 date=5 missing: _n_=6 date=6 missing: _n_=7 date=7 missing: _n_=8 date=8 missing: _n_=9 date=9 missing: _n_=10 date=10 missing: _n_=11 date=11 missing: _n_=12 date=12 not missing: _n_=13 date=13 not missing: _n_=14 date=14 not missing: _n_=15 date=15 not missing: _n_=16 date=16 not missing: _n_=17 date=17 not missing: _n_=18 date=18 not missing: _n_=19 date=19 not missing: _n_=20 date=20 note: missing values generated result of performing operation on missing values. each place given by: (number of times) @ (line):(column). 12 @ 85:6 note: there 20 observations read data set work.have. note: data set work.want has 20 observations , 2 variables.
one way avoid problem add block (untested):
if lag12 (jobboardid) eq jobboardid , _n_> 12 do; if intck('month', from, date) eq 12 do; till = date; rate = (sales - oldsales) / oldsales; output; end; end;
Comments
Post a Comment