Creating time specific dummy variables

Accepted Solution Solved
Reply
Contributor
Posts: 30
Accepted Solution

Creating time specific dummy variables

hi guys,

i am stuck with coming up with a CODE for sas with creating time specific dummy variables. I am new to SAS hope someone can help me out! Smiley Happy This is my problem,

I want to create dummy's for months before and after the birthday month of when they turn 55 years of age of individuals(given by ID). I have created a dummy for bday month (see below attached  sample file). In the example i have a person 54 in 2009 , when he reaches his bday month '10' i assign this to be '0', now i want 12 months after to be '0' as one variable and 3 months before as '0' given as a separate dummy variable. Can i get a very simple code to do this for many individuals (given be several ID's).

thanks in  advance! Smiley Happy

- jessica

IDyearmonthdayAGEBday_m55_dummybef_3monthsaft_12months
120091154101
120091254101
120091354101
120091554101
120091654101
120091754101
120091854101
120091954101
1200911054101
1200911154101
1200911254101
1200911354101
1200911454101
1200911554101
1200911654101
1200911754101
1200911854101
1200911954101
1200912054101
1200912154101
1200912254101
1200912354101
1200912454101
1200912554101
1200912654101
1200912754101
1200912854101
1200912954101
1200913054101
1200913154101
120092154101
120092254101
120092354101
120092454101
120092554101
120092654101
120092754101
120092854101
120092954101
1200921054101
1200921154101
1200921254101
1200921354101
1200921454101
1200921554101
1200921654101
1200921754101
1200921854101
1200921954101
1200922054101
1200922154101
1200922254101
1200922354101
1200922454101
1200922554101
1200922654101
1200922754101
1200922854101
120093254101
120093354101
120093454101
120093554101
120093654101
120093754101
120093854101
120093954101
1200931054101
1200931154101
1200931254101
1200931854101
1200931954101
1200932054101
1200932154101
1200932254101
1200932354101
1200932454101
1200932554101
1200932654101
1200932754101
1200932854101
1200932954101
1200933054101
1200933154101
120094154101
120094254101
120094354101
120094454101
120094554101
120094654101
120094754101
120094854101
120094954101
1200941054101
1200941154101
1200941254101
1200941354101
1200941454101
1200941554101
1200941654101
1200941854101
1200941954101
1200942054101
1200942154101
1200942254101
1200942354101
1200942454101
1200942554101
1200942654101
1200942754101
1200942854101
1200942954101
1200943054101
120095154101
120095254101
120095354101
120095454101
120095554101
120095654101
120095754101
120095854101
120095954101
1200951054101
1200951154101
1200951254101
1200951354101
1200951454101
1200951554101
1200951654101
1200951754101
1200951854101
1200951954101
1200952054101
1200952154101
1200952254101
1200952354101
1200952454101
1200952554101
1200952654101
1200952754101
1200952854101
1200952954101
1200953054101
1200953154101
120096154101
120096254101
120096354101
120096454101
120096554101
120096654101
120096754101
120096854101
120096954101
1200961054101
1200961154101
1200961254101
1200961354101
1200961454101
1200961554101
1200961654101
1200961754101
1200961854101
1200961954101
1200962054101
1200962154101
1200962254101
1200962354101
1200962454101
1200962554101
1200962654101
1200962754101
1200962854101
1200962954101
1200963054101
120097154101
120097254101
120097354101
120097454101
120097554101
120097654101
120097754101
120097854101
120097954101
1200971054101
1200971154101
1200971254101
1200971554101
1200971654101
1200971754101
1200971854101
1200971954101
1200972054101
1200972154101
1200972254101
1200972354101
1200972454101
1200972554101
1200972654101
1200972754101
1200972854101
1200972954101
1200973054101
1200973154101
120098154101
120098254101
120098354101
120098454101
120098554101
120098654101
120098754101
120098854101
120098954101
1200981054101
1200981154101
1200981254101
1200981354101
1200981454101
1200981554101
1200981654101
1200981754101
1200981854101
1200981954101
1200982054101
1200982154101
1200982254101
1200982354101
1200982454101
1200982554101
1200982654101
1200982754101
1200982854101
1200982954101
1200983054101
1200983154101
120099154101
120099254101
120099354101
120099454101
120099554101
120099654101
120099754101
120099854101
120099954101
1200991054101
1200991154101
1200991254101
1200991354101
1200991454101
1200991554101
1200991654101
1200991754101
1200991854101
1200991954101
1200992054101
1200992154101
1200992254101
1200992354101
1200992454101
1200992554101
1200992654101
1200992754101
1200992854101
1200992954101
1200993054101
1200910154100
1200910254100
1200910354100
1200910454100
1200910554100
1200910754100
1200910854100
1200910954100
12009101054100
12009101154100
12009101254100
12009101354100
12009101454100
12009101554100
12009101654100
12009101954100
12009102054100
12009102154100
12009102254100
12009102354100
12009102454100
12009102554100
12009102654100
12009102754100
12009102854100
12009102954100
12009103054100
12009103154100
1200911154101
1200911254101
1200911354101
1200911454101
1200911554101
1200911654101
1200911754101
1200911854101
1200911954101
12009111054101
12009111154101
12009111254101
12009111354101
12009111454101
12009111554101
12009111654101
12009111754101
12009111854101
12009111954101
12009112054101
12009112154101
12009112254101
12009112354101
12009112454101
12009112554101
12009112654101
12009112754101
12009112854101
12009113054101
120101154101
120101254101
120101354101
120101454101
120101554101
120101654101
120101754101
120101854101
120101954101
1201011054101
1201011154101
1201011254101
1201011354101
1201011454101
1201011554101
1201011654101
1201011754101
1201011854101
1201011954101
1201012054101
1201012154101
1201012254101
1201012354101
1201012454101
1201012554101
1201012654101
1201012754101
1201012854101
1201012954101
1201013054101
1201013154101
120102154101
120102254101
120102354101
120102454101
120102554101
120102654101
120102754101
120102854101
120102954101
1201021054101
1201021154101
1201021254101
1201021354101
1201021454101
1201021554101
1201021654101
1201021754101
1201021854101
1201021954101
1201022054101
1201022154101
1201022254101
1201022354101
1201022454101
1201022554101
1201022654101
1201022754101
1201022854101
120103154101
120103254101
120103354101
120103454101
120103554101
120103654101
120103754101
120103854101
120103954101
1201031054101
1201031154101
1201031254101
1201031354101
1201031454101
1201031554101
1201031654101
1201031754101
1201031854101
1201031954101
1201032054101
1201032154101
1201032254101
1201032354101
1201032454101
1201032554101
1201032654101
1201032754101
1201032954101
1201033054101
1201033154101
120104154101
120104254101
120104354101
120104454101
120104554101
120104654101
120104754101
120104854101
120104954101
1201041054101
1201041154101
1201041254101
1201041354101
1201041554101
1201041654101
1201041754101
1201041854101
1201041954101
1201042054101
1201042154101
1201042254101
1201042354101
1201042454101
1201042554101
1201042654101
1201042754101
1201042854101
1201042954101
1201043054101
120105254101
120105354101
120105454101
120105554101
120105654101
120105754101
120105854101
120105954101
1201051054101
1201051154101
1201051254101
1201051354101
1201051454101
1201051554101
1201051654101
1201051754101
1201051854101
1201051954101
1201052054101
1201052154101
1201052254101
1201052354101
1201052454101
1201052554101
1201052654101
1201052754101
1201052854101
1201052954101
1201053054101
1201053154101
120106154101
120106254101
120106354101
120106454101
120106554101
1201062054101
1201062154101
1201062254101
1201062354101
1201062454101
1201062554101
1201062654101
1201062754101
1201062854101
1201062954101
1201063054101
120107154101
120107254101
120107354101
120107454101
120107554101
120107654101
120107754101
120107854101
120107954101
1201071054101
1201071254101
1201071354101
1201071454101
1201071554101
1201071654101
1201071754101
1201071854101
1201071954101
1201072054101
1201072154101
1201072254101
1201072354101
1201072454101
1201072554101
1201072654101
1201072754101
1201072854101
1201072954101
1201073054101
1201073154101
120108154101
120108254101
120108354101
120108454101
120108554101
120108654101
120108754101
120108854101
120108954101
1201081054101
1201081154101
1201081254101
1201081354101
1201081454101
1201081554101
1201081654101
1201081754101
1201081854101
1201081954101
1201082054101
1201082154101
1201082254101
1201082354101
1201082454101
1201082554101
1201082654101
120109154101
120109254101
120109354101
120109454101
120109554101
120109654101
120109754101
120109854101
120109954101
1201091054101
1201091154101
1201091254101
1201091354101
1201091454101
1201091554101
1201091654101
1201091754101
1201091854101
1201091954101
1201092054101
1201092154101
1201092254101
1201092354101
1201092454101
1201092554101
1201092654101
1201092754101
1201092854101
1201092954101
1201093054101
1201010154101
1201010254101
1201010354101
1201010454101
1201010554101
1201010654101
1201010754101
1201010854101
1201010954101
12010101054101
12010101154101
12010101254101
12010101354101
12010101454101
12010101554101
12010101654101
12010101754101
12010101854101
12010101954101
12010102054101
12010102154101
12010102254101
12010102354101
12010102454101
12010102554101
12010102654101
12010102754101
12010102854101
12010102954101
12010103054101
12010103154101
1201011154101
1201011254101
1201011354101
1201011454101
1201011554101
1201011754101
1201011854101
1201011954101
12010111054101
12010111154101
12010111254101
12010111354101
12010111454101
12010111554101
12010111654101
12010111754101
12010111854101
12010111954101
12010112054101
12010112154101
12010112254101
12010112354101
12010112454101
12010112554101
12010112654101
12010112754101
12010112854101
12010112954101
12010113054101
1201012154101
1201012254101
1201012354101
1201012454101
1201012554101
1201012654101
1201012754101
1201012854101
1201012954101
12010121054101
12010121254101
12010121554101
12010121654101
12010121754101
12010121854101
12010121954101
12010122054101
12010122154101
12010122254101
12010122354101
12010122454101
12010122554101
12010122654101
12010122754101
12010122854101
12010122954101
12010123054101
12010123154101

Accepted Solutions
Solution
‎11-04-2014 06:41 AM
Super User
Posts: 9,856

Re: Creating time specific dummy variables

Hi. My code only are only worked for your data i.e. 54 . How do I know what to do with 55 56 ?

Post your new data and new desired output .

Data temp ;
  Set Have ;
  if _55_dummy eq 0 then do;output;stop;end;
Run;
data bef_3months aft_12months;
 set temp;
 d=mdy(month,1,year);
 do i=intnx('month',d,-3) to d-1;
  output bef_3months;
 end;
 do i=d to intnx('month',d,11,'e');
  output aft_12months;
 end;
 format i date9.;
 keep id i;
run;
data want; 
if _n_ eq 1 then do;
 if 0 then set bef_3months;
 declare hash ha1(dataset:'bef_3months');
  ha1.definekey(all:'y');
  ha1.definedone();

 if 0 then set aft_12months;
 declare hash ha2(dataset:'aft_12months');
  ha2.definekey(all:'y');
  ha2.definedone();
end;
 set have;
 i=mdy(month,day,year);
bef_3months=ifn(ha1.check()=0,0,1);
aft_12months=ifn(ha2.check()=0,0,1);
drop i;
run;

Xia Keshan

View solution in original post


All Replies
Super Contributor
Posts: 339

Re: Creating time specific dummy variables

Try:


Data Have;
  Input ID year month day age bday_m _55_dummy;
  Datalines;
1 2009 1 1 54 10 1
1 2009 1 2 54 10 1
1 2009 1 3 54 10 1
1 2009 1 5 54 10 1
1 2009 1 6 54 10 1
1 2009 1 7 54 10 1
1 2009 1 8 54 10 1
1 2009 1 9 54 10 1
1 2009 1 10 54 10 1
1 2009 1 11 54 10 1
1 2009 1 12 54 10 1
1 2009 1 13 54 10 1
1 2009 1 14 54 10 1
1 2009 1 15 54 10 1
1 2009 1 16 54 10 1
1 2009 1 17 54 10 1
1 2009 1 18 54 10 1
1 2009 1 19 54 10 1
1 2009 1 20 54 10 1
1 2009 1 21 54 10 1
1 2009 1 22 54 10 1
1 2009 1 23 54 10 1
1 2009 1 24 54 10 1
1 2009 1 25 54 10 1
1 2009 1 26 54 10 1
1 2009 1 27 54 10 1
1 2009 1 28 54 10 1
1 2009 1 29 54 10 1
1 2009 1 30 54 10 1
1 2009 1 31 54 10 1
1 2009 2 1 54 10 1
1 2009 2 2 54 10 1
1 2009 2 3 54 10 1
1 2009 2 4 54 10 1
1 2009 2 5 54 10 1
1 2009 2 6 54 10 1
1 2009 2 7 54 10 1
1 2009 2 8 54 10 1
1 2009 2 9 54 10 1
1 2009 2 10 54 10 1
1 2009 2 11 54 10 1
1 2009 2 12 54 10 1
1 2009 2 13 54 10 1
1 2009 2 14 54 10 1
1 2009 2 15 54 10 1
1 2009 2 16 54 10 1
1 2009 2 17 54 10 1
1 2009 2 18 54 10 1
1 2009 2 19 54 10 1
1 2009 2 20 54 10 1
1 2009 2 21 54 10 1
1 2009 2 22 54 10 1
1 2009 2 23 54 10 1
1 2009 2 24 54 10 1
1 2009 2 25 54 10 1
1 2009 2 26 54 10 1
1 2009 2 27 54 10 1
1 2009 2 28 54 10 1
1 2009 3 2 54 10 1
1 2009 3 3 54 10 1
1 2009 3 4 54 10 1
1 2009 3 5 54 10 1
1 2009 3 6 54 10 1
1 2009 3 7 54 10 1
1 2009 3 8 54 10 1
1 2009 3 9 54 10 1
1 2009 3 10 54 10 1
1 2009 3 11 54 10 1
1 2009 3 12 54 10 1
1 2009 3 18 54 10 1
1 2009 3 19 54 10 1
1 2009 3 20 54 10 1
1 2009 3 21 54 10 1
1 2009 3 22 54 10 1
1 2009 3 23 54 10 1
1 2009 3 24 54 10 1
1 2009 3 25 54 10 1
1 2009 3 26 54 10 1
1 2009 3 27 54 10 1
1 2009 3 28 54 10 1
1 2009 3 29 54 10 1
1 2009 3 30 54 10 1
1 2009 3 31 54 10 1
1 2009 4 1 54 10 1
1 2009 4 2 54 10 1
1 2009 4 3 54 10 1
1 2009 4 4 54 10 1
1 2009 4 5 54 10 1
1 2009 4 6 54 10 1
1 2009 4 7 54 10 1
1 2009 4 8 54 10 1
1 2009 4 9 54 10 1
1 2009 4 10 54 10 1
1 2009 4 11 54 10 1
1 2009 4 12 54 10 1
1 2009 4 13 54 10 1
1 2009 4 14 54 10 1
1 2009 4 15 54 10 1
1 2009 4 16 54 10 1
1 2009 4 18 54 10 1
1 2009 4 19 54 10 1
1 2009 4 20 54 10 1
1 2009 4 21 54 10 1
1 2009 4 22 54 10 1
1 2009 4 23 54 10 1
1 2009 4 24 54 10 1
1 2009 4 25 54 10 1
1 2009 4 26 54 10 1
1 2009 4 27 54 10 1
1 2009 4 28 54 10 1
1 2009 4 29 54 10 1
1 2009 4 30 54 10 1
1 2009 5 1 54 10 1
1 2009 5 2 54 10 1
1 2009 5 3 54 10 1
1 2009 5 4 54 10 1
1 2009 5 5 54 10 1
1 2009 5 6 54 10 1
1 2009 5 7 54 10 1
1 2009 5 8 54 10 1
1 2009 5 9 54 10 1
1 2009 5 10 54 10 1
1 2009 5 11 54 10 1
1 2009 5 12 54 10 1
1 2009 5 13 54 10 1
1 2009 5 14 54 10 1
1 2009 5 15 54 10 1
1 2009 5 16 54 10 1
1 2009 5 17 54 10 1
1 2009 5 18 54 10 1
1 2009 5 19 54 10 1
1 2009 5 20 54 10 1
1 2009 5 21 54 10 1
1 2009 5 22 54 10 1
1 2009 5 23 54 10 1
1 2009 5 24 54 10 1
1 2009 5 25 54 10 1
1 2009 5 26 54 10 1
1 2009 5 27 54 10 1
1 2009 5 28 54 10 1
1 2009 5 29 54 10 1
1 2009 5 30 54 10 1
1 2009 5 31 54 10 1
1 2009 6 1 54 10 1
1 2009 6 2 54 10 1
1 2009 6 3 54 10 1
1 2009 6 4 54 10 1
1 2009 6 5 54 10 1
1 2009 6 6 54 10 1
1 2009 6 7 54 10 1
1 2009 6 8 54 10 1
1 2009 6 9 54 10 1
1 2009 6 10 54 10 1
1 2009 6 11 54 10 1
1 2009 6 12 54 10 1
1 2009 6 13 54 10 1
1 2009 6 14 54 10 1
1 2009 6 15 54 10 1
1 2009 6 16 54 10 1
1 2009 6 17 54 10 1
1 2009 6 18 54 10 1
1 2009 6 19 54 10 1
1 2009 6 20 54 10 1
1 2009 6 21 54 10 1
1 2009 6 22 54 10 1
1 2009 6 23 54 10 1
1 2009 6 24 54 10 1
1 2009 6 25 54 10 1
1 2009 6 26 54 10 1
1 2009 6 27 54 10 1
1 2009 6 28 54 10 1
1 2009 6 29 54 10 1
1 2009 6 30 54 10 1
1 2009 7 1 54 10 1
1 2009 7 2 54 10 1
1 2009 7 3 54 10 1
1 2009 7 4 54 10 1
1 2009 7 5 54 10 1
1 2009 7 6 54 10 1
1 2009 7 7 54 10 1
1 2009 7 8 54 10 1
1 2009 7 9 54 10 1
1 2009 7 10 54 10 1
1 2009 7 11 54 10 1
1 2009 7 12 54 10 1
1 2009 7 15 54 10 1
1 2009 7 16 54 10 1
1 2009 7 17 54 10 1
1 2009 7 18 54 10 1
1 2009 7 19 54 10 1
1 2009 7 20 54 10 1
1 2009 7 21 54 10 1
1 2009 7 22 54 10 1
1 2009 7 23 54 10 1
1 2009 7 24 54 10 1
1 2009 7 25 54 10 1
1 2009 7 26 54 10 1
1 2009 7 27 54 10 1
1 2009 7 28 54 10 1
1 2009 7 29 54 10 1
1 2009 7 30 54 10 1
1 2009 7 31 54 10 1
1 2009 8 1 54 10 1
1 2009 8 2 54 10 1
1 2009 8 3 54 10 1
1 2009 8 4 54 10 1
1 2009 8 5 54 10 1
1 2009 8 6 54 10 1
1 2009 8 7 54 10 1
1 2009 8 8 54 10 1
1 2009 8 9 54 10 1
1 2009 8 10 54 10 1
1 2009 8 11 54 10 1
1 2009 8 12 54 10 1
1 2009 8 13 54 10 1
1 2009 8 14 54 10 1
1 2009 8 15 54 10 1
1 2009 8 16 54 10 1
1 2009 8 17 54 10 1
1 2009 8 18 54 10 1
1 2009 8 19 54 10 1
1 2009 8 20 54 10 1
1 2009 8 21 54 10 1
1 2009 8 22 54 10 1
1 2009 8 23 54 10 1
1 2009 8 24 54 10 1
1 2009 8 25 54 10 1
1 2009 8 26 54 10 1
1 2009 8 27 54 10 1
1 2009 8 28 54 10 1
1 2009 8 29 54 10 1
1 2009 8 30 54 10 1
1 2009 8 31 54 10 1
1 2009 9 1 54 10 1
1 2009 9 2 54 10 1
1 2009 9 3 54 10 1
1 2009 9 4 54 10 1
1 2009 9 5 54 10 1
1 2009 9 6 54 10 1
1 2009 9 7 54 10 1
1 2009 9 8 54 10 1
1 2009 9 9 54 10 1
1 2009 9 10 54 10 1
1 2009 9 11 54 10 1
1 2009 9 12 54 10 1
1 2009 9 13 54 10 1
1 2009 9 14 54 10 1
1 2009 9 15 54 10 1
1 2009 9 16 54 10 1
1 2009 9 17 54 10 1
1 2009 9 18 54 10 1
1 2009 9 19 54 10 1
1 2009 9 20 54 10 1
1 2009 9 21 54 10 1
1 2009 9 22 54 10 1
1 2009 9 23 54 10 1
1 2009 9 24 54 10 1
1 2009 9 25 54 10 1
1 2009 9 26 54 10 1
1 2009 9 27 54 10 1
1 2009 9 28 54 10 1
1 2009 9 29 54 10 1
1 2009 9 30 54 10 1
1 2009 10 1 54 10 0
1 2009 10 2 54 10 0
1 2009 10 3 54 10 0
1 2009 10 4 54 10 0
1 2009 10 5 54 10 0
1 2009 10 7 54 10 0
1 2009 10 8 54 10 0
1 2009 10 9 54 10 0
1 2009 10 10 54 10 0
1 2009 10 11 54 10 0
1 2009 10 12 54 10 0
1 2009 10 13 54 10 0
1 2009 10 14 54 10 0
1 2009 10 15 54 10 0
1 2009 10 16 54 10 0
1 2009 10 19 54 10 0
1 2009 10 20 54 10 0
1 2009 10 21 54 10 0
1 2009 10 22 54 10 0
1 2009 10 23 54 10 0
1 2009 10 24 54 10 0
1 2009 10 25 54 10 0
1 2009 10 26 54 10 0
1 2009 10 27 54 10 0
1 2009 10 28 54 10 0
1 2009 10 29 54 10 0
1 2009 10 30 54 10 0
1 2009 10 31 54 10 0
1 2009 11 1 54 10 1
1 2009 11 2 54 10 1
1 2009 11 3 54 10 1
1 2009 11 4 54 10 1
1 2009 11 5 54 10 1
1 2009 11 6 54 10 1
1 2009 11 7 54 10 1
1 2009 11 8 54 10 1
1 2009 11 9 54 10 1
1 2009 11 10 54 10 1
1 2009 11 11 54 10 1
1 2009 11 12 54 10 1
1 2009 11 13 54 10 1
1 2009 11 14 54 10 1
1 2009 11 15 54 10 1
1 2009 11 16 54 10 1
1 2009 11 17 54 10 1
1 2009 11 18 54 10 1
1 2009 11 19 54 10 1
1 2009 11 20 54 10 1
1 2009 11 21 54 10 1
1 2009 11 22 54 10 1
1 2009 11 23 54 10 1
1 2009 11 24 54 10 1
1 2009 11 25 54 10 1
1 2009 11 26 54 10 1
1 2009 11 27 54 10 1
1 2009 11 28 54 10 1
1 2009 11 30 54 10 1
1 2010 1 1 54 10 1
1 2010 1 2 54 10 1
1 2010 1 3 54 10 1
1 2010 1 4 54 10 1
1 2010 1 5 54 10 1
1 2010 1 6 54 10 1
1 2010 1 7 54 10 1
1 2010 1 8 54 10 1
1 2010 1 9 54 10 1
1 2010 1 10 54 10 1
1 2010 1 11 54 10 1
1 2010 1 12 54 10 1
1 2010 1 13 54 10 1
1 2010 1 14 54 10 1
1 2010 1 15 54 10 1
1 2010 1 16 54 10 1
1 2010 1 17 54 10 1
1 2010 1 18 54 10 1
1 2010 1 19 54 10 1
1 2010 1 20 54 10 1
1 2010 1 21 54 10 1
1 2010 1 22 54 10 1
1 2010 1 23 54 10 1
1 2010 1 24 54 10 1
1 2010 1 25 54 10 1
1 2010 1 26 54 10 1
1 2010 1 27 54 10 1
1 2010 1 28 54 10 1
1 2010 1 29 54 10 1
1 2010 1 30 54 10 1
1 2010 1 31 54 10 1
1 2010 2 1 54 10 1
1 2010 2 2 54 10 1
1 2010 2 3 54 10 1
1 2010 2 4 54 10 1
1 2010 2 5 54 10 1
1 2010 2 6 54 10 1
1 2010 2 7 54 10 1
1 2010 2 8 54 10 1
1 2010 2 9 54 10 1
1 2010 2 10 54 10 1
1 2010 2 11 54 10 1
1 2010 2 12 54 10 1
1 2010 2 13 54 10 1
1 2010 2 14 54 10 1
1 2010 2 15 54 10 1
1 2010 2 16 54 10 1
1 2010 2 17 54 10 1
1 2010 2 18 54 10 1
1 2010 2 19 54 10 1
1 2010 2 20 54 10 1
1 2010 2 21 54 10 1
1 2010 2 22 54 10 1
1 2010 2 23 54 10 1
1 2010 2 24 54 10 1
1 2010 2 25 54 10 1
1 2010 2 26 54 10 1
1 2010 2 27 54 10 1
1 2010 2 28 54 10 1
1 2010 3 1 54 10 1
1 2010 3 2 54 10 1
1 2010 3 3 54 10 1
1 2010 3 4 54 10 1
1 2010 3 5 54 10 1
1 2010 3 6 54 10 1
1 2010 3 7 54 10 1
1 2010 3 8 54 10 1
1 2010 3 9 54 10 1
1 2010 3 10 54 10 1
1 2010 3 11 54 10 1
1 2010 3 12 54 10 1
1 2010 3 13 54 10 1
1 2010 3 14 54 10 1
1 2010 3 15 54 10 1
1 2010 3 16 54 10 1
1 2010 3 17 54 10 1
1 2010 3 18 54 10 1
1 2010 3 19 54 10 1
1 2010 3 20 54 10 1
1 2010 3 21 54 10 1
1 2010 3 22 54 10 1
1 2010 3 23 54 10 1
1 2010 3 24 54 10 1
1 2010 3 25 54 10 1
1 2010 3 26 54 10 1
1 2010 3 27 54 10 1
1 2010 3 29 54 10 1
1 2010 3 30 54 10 1
1 2010 3 31 54 10 1
1 2010 4 1 54 10 1
1 2010 4 2 54 10 1
1 2010 4 3 54 10 1
1 2010 4 4 54 10 1
1 2010 4 5 54 10 1
1 2010 4 6 54 10 1
1 2010 4 7 54 10 1
1 2010 4 8 54 10 1
1 2010 4 9 54 10 1
1 2010 4 10 54 10 1
1 2010 4 11 54 10 1
1 2010 4 12 54 10 1
1 2010 4 13 54 10 1
1 2010 4 15 54 10 1
1 2010 4 16 54 10 1
1 2010 4 17 54 10 1
1 2010 4 18 54 10 1
1 2010 4 19 54 10 1
1 2010 4 20 54 10 1
1 2010 4 21 54 10 1
1 2010 4 22 54 10 1
1 2010 4 23 54 10 1
1 2010 4 24 54 10 1
1 2010 4 25 54 10 1
1 2010 4 26 54 10 1
1 2010 4 27 54 10 1
1 2010 4 28 54 10 1
1 2010 4 29 54 10 1
1 2010 4 30 54 10 1
1 2010 5 2 54 10 1
1 2010 5 3 54 10 1
1 2010 5 4 54 10 1
1 2010 5 5 54 10 1
1 2010 5 6 54 10 1
1 2010 5 7 54 10 1
1 2010 5 8 54 10 1
1 2010 5 9 54 10 1
1 2010 5 10 54 10 1
1 2010 5 11 54 10 1
1 2010 5 12 54 10 1
1 2010 5 13 54 10 1
1 2010 5 14 54 10 1
1 2010 5 15 54 10 1
1 2010 5 16 54 10 1
1 2010 5 17 54 10 1
1 2010 5 18 54 10 1
1 2010 5 19 54 10 1
1 2010 5 20 54 10 1
1 2010 5 21 54 10 1
1 2010 5 22 54 10 1
1 2010 5 23 54 10 1
1 2010 5 24 54 10 1
1 2010 5 25 54 10 1
1 2010 5 26 54 10 1
1 2010 5 27 54 10 1
1 2010 5 28 54 10 1
1 2010 5 29 54 10 1
1 2010 5 30 54 10 1
1 2010 5 31 54 10 1
1 2010 6 1 54 10 1
1 2010 6 2 54 10 1
1 2010 6 3 54 10 1
1 2010 6 4 54 10 1
1 2010 6 5 54 10 1
1 2010 6 20 54 10 1
1 2010 6 21 54 10 1
1 2010 6 22 54 10 1
1 2010 6 23 54 10 1
1 2010 6 24 54 10 1
1 2010 6 25 54 10 1
1 2010 6 26 54 10 1
1 2010 6 27 54 10 1
1 2010 6 28 54 10 1
1 2010 6 29 54 10 1
1 2010 6 30 54 10 1
1 2010 7 1 54 10 1
1 2010 7 2 54 10 1
1 2010 7 3 54 10 1
1 2010 7 4 54 10 1
1 2010 7 5 54 10 1
1 2010 7 6 54 10 1
1 2010 7 7 54 10 1
1 2010 7 8 54 10 1
1 2010 7 9 54 10 1
1 2010 7 10 54 10 1
1 2010 7 12 54 10 1
1 2010 7 13 54 10 1
1 2010 7 14 54 10 1
1 2010 7 15 54 10 1
1 2010 7 16 54 10 1
1 2010 7 17 54 10 1
1 2010 7 18 54 10 1
1 2010 7 19 54 10 1
1 2010 7 20 54 10 1
1 2010 7 21 54 10 1
1 2010 7 22 54 10 1
1 2010 7 23 54 10 1
1 2010 7 24 54 10 1
1 2010 7 25 54 10 1
1 2010 7 26 54 10 1
1 2010 7 27 54 10 1
1 2010 7 28 54 10 1
1 2010 7 29 54 10 1
1 2010 7 30 54 10 1
1 2010 7 31 54 10 1
1 2010 8 1 54 10 1
1 2010 8 2 54 10 1
1 2010 8 3 54 10 1
1 2010 8 4 54 10 1
1 2010 8 5 54 10 1
1 2010 8 6 54 10 1
1 2010 8 7 54 10 1
1 2010 8 8 54 10 1
1 2010 8 9 54 10 1
1 2010 8 10 54 10 1
1 2010 8 11 54 10 1
1 2010 8 12 54 10 1
1 2010 8 13 54 10 1
1 2010 8 14 54 10 1
1 2010 8 15 54 10 1
1 2010 8 16 54 10 1
1 2010 8 17 54 10 1
1 2010 8 18 54 10 1
1 2010 8 19 54 10 1
1 2010 8 20 54 10 1
1 2010 8 21 54 10 1
1 2010 8 22 54 10 1
1 2010 8 23 54 10 1
1 2010 8 24 54 10 1
1 2010 8 25 54 10 1
1 2010 8 26 54 10 1
1 2010 9 1 54 10 1
1 2010 9 2 54 10 1
1 2010 9 3 54 10 1
1 2010 9 4 54 10 1
1 2010 9 5 54 10 1
1 2010 9 6 54 10 1
1 2010 9 7 54 10 1
1 2010 9 8 54 10 1
1 2010 9 9 54 10 1
1 2010 9 10 54 10 1
1 2010 9 11 54 10 1
1 2010 9 12 54 10 1
1 2010 9 13 54 10 1
1 2010 9 14 54 10 1
1 2010 9 15 54 10 1
1 2010 9 16 54 10 1
1 2010 9 17 54 10 1
1 2010 9 18 54 10 1
1 2010 9 19 54 10 1
1 2010 9 20 54 10 1
1 2010 9 21 54 10 1
1 2010 9 22 54 10 1
1 2010 9 23 54 10 1
1 2010 9 24 54 10 1
1 2010 9 25 54 10 1
1 2010 9 26 54 10 1
1 2010 9 27 54 10 1
1 2010 9 28 54 10 1
1 2010 9 29 54 10 1
1 2010 9 30 54 10 1
1 2010 10 1 54 10 1
1 2010 10 2 54 10 1
1 2010 10 3 54 10 1
1 2010 10 4 54 10 1
1 2010 10 5 54 10 1
1 2010 10 6 54 10 1
1 2010 10 7 54 10 1
1 2010 10 8 54 10 1
1 2010 10 9 54 10 1
1 2010 10 10 54 10 1
1 2010 10 11 54 10 1
1 2010 10 12 54 10 1
1 2010 10 13 54 10 1
1 2010 10 14 54 10 1
1 2010 10 15 54 10 1
1 2010 10 16 54 10 1
1 2010 10 17 54 10 1
1 2010 10 18 54 10 1
1 2010 10 19 54 10 1
1 2010 10 20 54 10 1
1 2010 10 21 54 10 1
1 2010 10 22 54 10 1
1 2010 10 23 54 10 1
1 2010 10 24 54 10 1
1 2010 10 25 54 10 1
1 2010 10 26 54 10 1
1 2010 10 27 54 10 1
1 2010 10 28 54 10 1
1 2010 10 29 54 10 1
1 2010 10 30 54 10 1
1 2010 10 31 54 10 1
1 2010 11 1 54 10 1
1 2010 11 2 54 10 1
1 2010 11 3 54 10 1
1 2010 11 4 54 10 1
1 2010 11 5 54 10 1
1 2010 11 7 54 10 1
1 2010 11 8 54 10 1
1 2010 11 9 54 10 1
1 2010 11 10 54 10 1
1 2010 11 11 54 10 1
1 2010 11 12 54 10 1
1 2010 11 13 54 10 1
1 2010 11 14 54 10 1
1 2010 11 15 54 10 1
1 2010 11 16 54 10 1
1 2010 11 17 54 10 1
1 2010 11 18 54 10 1
1 2010 11 19 54 10 1
1 2010 11 20 54 10 1
1 2010 11 21 54 10 1
1 2010 11 22 54 10 1
1 2010 11 23 54 10 1
1 2010 11 24 54 10 1
1 2010 11 25 54 10 1
1 2010 11 26 54 10 1
1 2010 11 27 54 10 1
1 2010 11 28 54 10 1
1 2010 11 29 54 10 1
1 2010 11 30 54 10 1
1 2010 12 1 54 10 1
1 2010 12 2 54 10 1
1 2010 12 3 54 10 1
1 2010 12 4 54 10 1
1 2010 12 5 54 10 1
1 2010 12 6 54 10 1
1 2010 12 7 54 10 1
1 2010 12 8 54 10 1
1 2010 12 9 54 10 1
1 2010 12 10 54 10 1
1 2010 12 12 54 10 1
1 2010 12 15 54 10 1
1 2010 12 16 54 10 1
1 2010 12 17 54 10 1
1 2010 12 18 54 10 1
1 2010 12 19 54 10 1
1 2010 12 20 54 10 1
1 2010 12 21 54 10 1
1 2010 12 22 54 10 1
1 2010 12 23 54 10 1
1 2010 12 24 54 10 1
1 2010 12 25 54 10 1
1 2010 12 26 54 10 1
1 2010 12 27 54 10 1
1 2010 12 28 54 10 1
1 2010 12 29 54 10 1
1 2010 12 30 54 10 1
1 2010 12 31 54 10 1
;
Run;

Data Help (Keep=ID bday_date);
  Set Have (Where=(_55_dummy eq 0));
  bday_date=MDY(month, 1, year); Format bday_date Date9.;
Run;

Proc Sort Data=Help Nodupkey;
  By ID;
Run;

Data Want (Drop=bday_date date);
  Merge Have (in=inHave) Help (in=inHelp);
  By ID;
  date=MDY(month,1,year); Format date Date9.;
  If (IntCK('month',bday_date,date) le 12) & (IntCK('month',bday_date,date) ge -3) Then dummy_new=0; Else dummy_new=1;
  If inHave Then Output;
Run;

Super User
Posts: 9,856

Re: Creating time specific dummy variables

Data Have;
  Input ID year month day age bday_m _55_dummy;
  Datalines;
1 2009 1 1 54 10 1
1 2009 1 2 54 10 1
1 2009 1 3 54 10 1
1 2009 1 5 54 10 1
1 2009 1 6 54 10 1
1 2009 1 7 54 10 1
1 2009 1 8 54 10 1
1 2009 1 9 54 10 1
1 2009 1 10 54 10 1
1 2009 1 11 54 10 1
1 2009 1 12 54 10 1
1 2009 1 13 54 10 1
1 2009 1 14 54 10 1
1 2009 1 15 54 10 1
1 2009 1 16 54 10 1
1 2009 1 17 54 10 1
1 2009 1 18 54 10 1
1 2009 1 19 54 10 1
1 2009 1 20 54 10 1
1 2009 1 21 54 10 1
1 2009 1 22 54 10 1
1 2009 1 23 54 10 1
1 2009 1 24 54 10 1
1 2009 1 25 54 10 1
1 2009 1 26 54 10 1
1 2009 1 27 54 10 1
1 2009 1 28 54 10 1
1 2009 1 29 54 10 1
1 2009 1 30 54 10 1
1 2009 1 31 54 10 1
1 2009 2 1 54 10 1
1 2009 2 2 54 10 1
1 2009 2 3 54 10 1
1 2009 2 4 54 10 1
1 2009 2 5 54 10 1
1 2009 2 6 54 10 1
1 2009 2 7 54 10 1
1 2009 2 8 54 10 1
1 2009 2 9 54 10 1
1 2009 2 10 54 10 1
1 2009 2 11 54 10 1
1 2009 2 12 54 10 1
1 2009 2 13 54 10 1
1 2009 2 14 54 10 1
1 2009 2 15 54 10 1
1 2009 2 16 54 10 1
1 2009 2 17 54 10 1
1 2009 2 18 54 10 1
1 2009 2 19 54 10 1
1 2009 2 20 54 10 1
1 2009 2 21 54 10 1
1 2009 2 22 54 10 1
1 2009 2 23 54 10 1
1 2009 2 24 54 10 1
1 2009 2 25 54 10 1
1 2009 2 26 54 10 1
1 2009 2 27 54 10 1
1 2009 2 28 54 10 1
1 2009 3 2 54 10 1
1 2009 3 3 54 10 1
1 2009 3 4 54 10 1
1 2009 3 5 54 10 1
1 2009 3 6 54 10 1
1 2009 3 7 54 10 1
1 2009 3 8 54 10 1
1 2009 3 9 54 10 1
1 2009 3 10 54 10 1
1 2009 3 11 54 10 1
1 2009 3 12 54 10 1
1 2009 3 18 54 10 1
1 2009 3 19 54 10 1
1 2009 3 20 54 10 1
1 2009 3 21 54 10 1
1 2009 3 22 54 10 1
1 2009 3 23 54 10 1
1 2009 3 24 54 10 1
1 2009 3 25 54 10 1
1 2009 3 26 54 10 1
1 2009 3 27 54 10 1
1 2009 3 28 54 10 1
1 2009 3 29 54 10 1
1 2009 3 30 54 10 1
1 2009 3 31 54 10 1
1 2009 4 1 54 10 1
1 2009 4 2 54 10 1
1 2009 4 3 54 10 1
1 2009 4 4 54 10 1
1 2009 4 5 54 10 1
1 2009 4 6 54 10 1
1 2009 4 7 54 10 1
1 2009 4 8 54 10 1
1 2009 4 9 54 10 1
1 2009 4 10 54 10 1
1 2009 4 11 54 10 1
1 2009 4 12 54 10 1
1 2009 4 13 54 10 1
1 2009 4 14 54 10 1
1 2009 4 15 54 10 1
1 2009 4 16 54 10 1
1 2009 4 18 54 10 1
1 2009 4 19 54 10 1
1 2009 4 20 54 10 1
1 2009 4 21 54 10 1
1 2009 4 22 54 10 1
1 2009 4 23 54 10 1
1 2009 4 24 54 10 1
1 2009 4 25 54 10 1
1 2009 4 26 54 10 1
1 2009 4 27 54 10 1
1 2009 4 28 54 10 1
1 2009 4 29 54 10 1
1 2009 4 30 54 10 1
1 2009 5 1 54 10 1
1 2009 5 2 54 10 1
1 2009 5 3 54 10 1
1 2009 5 4 54 10 1
1 2009 5 5 54 10 1
1 2009 5 6 54 10 1
1 2009 5 7 54 10 1
1 2009 5 8 54 10 1
1 2009 5 9 54 10 1
1 2009 5 10 54 10 1
1 2009 5 11 54 10 1
1 2009 5 12 54 10 1
1 2009 5 13 54 10 1
1 2009 5 14 54 10 1
1 2009 5 15 54 10 1
1 2009 5 16 54 10 1
1 2009 5 17 54 10 1
1 2009 5 18 54 10 1
1 2009 5 19 54 10 1
1 2009 5 20 54 10 1
1 2009 5 21 54 10 1
1 2009 5 22 54 10 1
1 2009 5 23 54 10 1
1 2009 5 24 54 10 1
1 2009 5 25 54 10 1
1 2009 5 26 54 10 1
1 2009 5 27 54 10 1
1 2009 5 28 54 10 1
1 2009 5 29 54 10 1
1 2009 5 30 54 10 1
1 2009 5 31 54 10 1
1 2009 6 1 54 10 1
1 2009 6 2 54 10 1
1 2009 6 3 54 10 1
1 2009 6 4 54 10 1
1 2009 6 5 54 10 1
1 2009 6 6 54 10 1
1 2009 6 7 54 10 1
1 2009 6 8 54 10 1
1 2009 6 9 54 10 1
1 2009 6 10 54 10 1
1 2009 6 11 54 10 1
1 2009 6 12 54 10 1
1 2009 6 13 54 10 1
1 2009 6 14 54 10 1
1 2009 6 15 54 10 1
1 2009 6 16 54 10 1
1 2009 6 17 54 10 1
1 2009 6 18 54 10 1
1 2009 6 19 54 10 1
1 2009 6 20 54 10 1
1 2009 6 21 54 10 1
1 2009 6 22 54 10 1
1 2009 6 23 54 10 1
1 2009 6 24 54 10 1
1 2009 6 25 54 10 1
1 2009 6 26 54 10 1
1 2009 6 27 54 10 1
1 2009 6 28 54 10 1
1 2009 6 29 54 10 1
1 2009 6 30 54 10 1
1 2009 7 1 54 10 1
1 2009 7 2 54 10 1
1 2009 7 3 54 10 1
1 2009 7 4 54 10 1
1 2009 7 5 54 10 1
1 2009 7 6 54 10 1
1 2009 7 7 54 10 1
1 2009 7 8 54 10 1
1 2009 7 9 54 10 1
1 2009 7 10 54 10 1
1 2009 7 11 54 10 1
1 2009 7 12 54 10 1
1 2009 7 15 54 10 1
1 2009 7 16 54 10 1
1 2009 7 17 54 10 1
1 2009 7 18 54 10 1
1 2009 7 19 54 10 1
1 2009 7 20 54 10 1
1 2009 7 21 54 10 1
1 2009 7 22 54 10 1
1 2009 7 23 54 10 1
1 2009 7 24 54 10 1
1 2009 7 25 54 10 1
1 2009 7 26 54 10 1
1 2009 7 27 54 10 1
1 2009 7 28 54 10 1
1 2009 7 29 54 10 1
1 2009 7 30 54 10 1
1 2009 7 31 54 10 1
1 2009 8 1 54 10 1
1 2009 8 2 54 10 1
1 2009 8 3 54 10 1
1 2009 8 4 54 10 1
1 2009 8 5 54 10 1
1 2009 8 6 54 10 1
1 2009 8 7 54 10 1
1 2009 8 8 54 10 1
1 2009 8 9 54 10 1
1 2009 8 10 54 10 1
1 2009 8 11 54 10 1
1 2009 8 12 54 10 1
1 2009 8 13 54 10 1
1 2009 8 14 54 10 1
1 2009 8 15 54 10 1
1 2009 8 16 54 10 1
1 2009 8 17 54 10 1
1 2009 8 18 54 10 1
1 2009 8 19 54 10 1
1 2009 8 20 54 10 1
1 2009 8 21 54 10 1
1 2009 8 22 54 10 1
1 2009 8 23 54 10 1
1 2009 8 24 54 10 1
1 2009 8 25 54 10 1
1 2009 8 26 54 10 1
1 2009 8 27 54 10 1
1 2009 8 28 54 10 1
1 2009 8 29 54 10 1
1 2009 8 30 54 10 1
1 2009 8 31 54 10 1
1 2009 9 1 54 10 1
1 2009 9 2 54 10 1
1 2009 9 3 54 10 1
1 2009 9 4 54 10 1
1 2009 9 5 54 10 1
1 2009 9 6 54 10 1
1 2009 9 7 54 10 1
1 2009 9 8 54 10 1
1 2009 9 9 54 10 1
1 2009 9 10 54 10 1
1 2009 9 11 54 10 1
1 2009 9 12 54 10 1
1 2009 9 13 54 10 1
1 2009 9 14 54 10 1
1 2009 9 15 54 10 1
1 2009 9 16 54 10 1
1 2009 9 17 54 10 1
1 2009 9 18 54 10 1
1 2009 9 19 54 10 1
1 2009 9 20 54 10 1
1 2009 9 21 54 10 1
1 2009 9 22 54 10 1
1 2009 9 23 54 10 1
1 2009 9 24 54 10 1
1 2009 9 25 54 10 1
1 2009 9 26 54 10 1
1 2009 9 27 54 10 1
1 2009 9 28 54 10 1
1 2009 9 29 54 10 1
1 2009 9 30 54 10 1
1 2009 10 1 54 10 0
1 2009 10 2 54 10 0
1 2009 10 3 54 10 0
1 2009 10 4 54 10 0
1 2009 10 5 54 10 0
1 2009 10 7 54 10 0
1 2009 10 8 54 10 0
1 2009 10 9 54 10 0
1 2009 10 10 54 10 0
1 2009 10 11 54 10 0
1 2009 10 12 54 10 0
1 2009 10 13 54 10 0
1 2009 10 14 54 10 0
1 2009 10 15 54 10 0
1 2009 10 16 54 10 0
1 2009 10 19 54 10 0
1 2009 10 20 54 10 0
1 2009 10 21 54 10 0
1 2009 10 22 54 10 0
1 2009 10 23 54 10 0
1 2009 10 24 54 10 0
1 2009 10 25 54 10 0
1 2009 10 26 54 10 0
1 2009 10 27 54 10 0
1 2009 10 28 54 10 0
1 2009 10 29 54 10 0
1 2009 10 30 54 10 0
1 2009 10 31 54 10 0
1 2009 11 1 54 10 1
1 2009 11 2 54 10 1
1 2009 11 3 54 10 1
1 2009 11 4 54 10 1
1 2009 11 5 54 10 1
1 2009 11 6 54 10 1
1 2009 11 7 54 10 1
1 2009 11 8 54 10 1
1 2009 11 9 54 10 1
1 2009 11 10 54 10 1
1 2009 11 11 54 10 1
1 2009 11 12 54 10 1
1 2009 11 13 54 10 1
1 2009 11 14 54 10 1
1 2009 11 15 54 10 1
1 2009 11 16 54 10 1
1 2009 11 17 54 10 1
1 2009 11 18 54 10 1
1 2009 11 19 54 10 1
1 2009 11 20 54 10 1
1 2009 11 21 54 10 1
1 2009 11 22 54 10 1
1 2009 11 23 54 10 1
1 2009 11 24 54 10 1
1 2009 11 25 54 10 1
1 2009 11 26 54 10 1
1 2009 11 27 54 10 1
1 2009 11 28 54 10 1
1 2009 11 30 54 10 1
1 2010 1 1 54 10 1
1 2010 1 2 54 10 1
1 2010 1 3 54 10 1
1 2010 1 4 54 10 1
1 2010 1 5 54 10 1
1 2010 1 6 54 10 1
1 2010 1 7 54 10 1
1 2010 1 8 54 10 1
1 2010 1 9 54 10 1
1 2010 1 10 54 10 1
1 2010 1 11 54 10 1
1 2010 1 12 54 10 1
1 2010 1 13 54 10 1
1 2010 1 14 54 10 1
1 2010 1 15 54 10 1
1 2010 1 16 54 10 1
1 2010 1 17 54 10 1
1 2010 1 18 54 10 1
1 2010 1 19 54 10 1
1 2010 1 20 54 10 1
1 2010 1 21 54 10 1
1 2010 1 22 54 10 1
1 2010 1 23 54 10 1
1 2010 1 24 54 10 1
1 2010 1 25 54 10 1
1 2010 1 26 54 10 1
1 2010 1 27 54 10 1
1 2010 1 28 54 10 1
1 2010 1 29 54 10 1
1 2010 1 30 54 10 1
1 2010 1 31 54 10 1
1 2010 2 1 54 10 1
1 2010 2 2 54 10 1
1 2010 2 3 54 10 1
1 2010 2 4 54 10 1
1 2010 2 5 54 10 1
1 2010 2 6 54 10 1
1 2010 2 7 54 10 1
1 2010 2 8 54 10 1
1 2010 2 9 54 10 1
1 2010 2 10 54 10 1
1 2010 2 11 54 10 1
1 2010 2 12 54 10 1
1 2010 2 13 54 10 1
1 2010 2 14 54 10 1
1 2010 2 15 54 10 1
1 2010 2 16 54 10 1
1 2010 2 17 54 10 1
1 2010 2 18 54 10 1
1 2010 2 19 54 10 1
1 2010 2 20 54 10 1
1 2010 2 21 54 10 1
1 2010 2 22 54 10 1
1 2010 2 23 54 10 1
1 2010 2 24 54 10 1
1 2010 2 25 54 10 1
1 2010 2 26 54 10 1
1 2010 2 27 54 10 1
1 2010 2 28 54 10 1
1 2010 3 1 54 10 1
1 2010 3 2 54 10 1
1 2010 3 3 54 10 1
1 2010 3 4 54 10 1
1 2010 3 5 54 10 1
1 2010 3 6 54 10 1
1 2010 3 7 54 10 1
1 2010 3 8 54 10 1
1 2010 3 9 54 10 1
1 2010 3 10 54 10 1
1 2010 3 11 54 10 1
1 2010 3 12 54 10 1
1 2010 3 13 54 10 1
1 2010 3 14 54 10 1
1 2010 3 15 54 10 1
1 2010 3 16 54 10 1
1 2010 3 17 54 10 1
1 2010 3 18 54 10 1
1 2010 3 19 54 10 1
1 2010 3 20 54 10 1
1 2010 3 21 54 10 1
1 2010 3 22 54 10 1
1 2010 3 23 54 10 1
1 2010 3 24 54 10 1
1 2010 3 25 54 10 1
1 2010 3 26 54 10 1
1 2010 3 27 54 10 1
1 2010 3 29 54 10 1
1 2010 3 30 54 10 1
1 2010 3 31 54 10 1
1 2010 4 1 54 10 1
1 2010 4 2 54 10 1
1 2010 4 3 54 10 1
1 2010 4 4 54 10 1
1 2010 4 5 54 10 1
1 2010 4 6 54 10 1
1 2010 4 7 54 10 1
1 2010 4 8 54 10 1
1 2010 4 9 54 10 1
1 2010 4 10 54 10 1
1 2010 4 11 54 10 1
1 2010 4 12 54 10 1
1 2010 4 13 54 10 1
1 2010 4 15 54 10 1
1 2010 4 16 54 10 1
1 2010 4 17 54 10 1
1 2010 4 18 54 10 1
1 2010 4 19 54 10 1
1 2010 4 20 54 10 1
1 2010 4 21 54 10 1
1 2010 4 22 54 10 1
1 2010 4 23 54 10 1
1 2010 4 24 54 10 1
1 2010 4 25 54 10 1
1 2010 4 26 54 10 1
1 2010 4 27 54 10 1
1 2010 4 28 54 10 1
1 2010 4 29 54 10 1
1 2010 4 30 54 10 1
1 2010 5 2 54 10 1
1 2010 5 3 54 10 1
1 2010 5 4 54 10 1
1 2010 5 5 54 10 1
1 2010 5 6 54 10 1
1 2010 5 7 54 10 1
1 2010 5 8 54 10 1
1 2010 5 9 54 10 1
1 2010 5 10 54 10 1
1 2010 5 11 54 10 1
1 2010 5 12 54 10 1
1 2010 5 13 54 10 1
1 2010 5 14 54 10 1
1 2010 5 15 54 10 1
1 2010 5 16 54 10 1
1 2010 5 17 54 10 1
1 2010 5 18 54 10 1
1 2010 5 19 54 10 1
1 2010 5 20 54 10 1
1 2010 5 21 54 10 1
1 2010 5 22 54 10 1
1 2010 5 23 54 10 1
1 2010 5 24 54 10 1
1 2010 5 25 54 10 1
1 2010 5 26 54 10 1
1 2010 5 27 54 10 1
1 2010 5 28 54 10 1
1 2010 5 29 54 10 1
1 2010 5 30 54 10 1
1 2010 5 31 54 10 1
1 2010 6 1 54 10 1
1 2010 6 2 54 10 1
1 2010 6 3 54 10 1
1 2010 6 4 54 10 1
1 2010 6 5 54 10 1
1 2010 6 20 54 10 1
1 2010 6 21 54 10 1
1 2010 6 22 54 10 1
1 2010 6 23 54 10 1
1 2010 6 24 54 10 1
1 2010 6 25 54 10 1
1 2010 6 26 54 10 1
1 2010 6 27 54 10 1
1 2010 6 28 54 10 1
1 2010 6 29 54 10 1
1 2010 6 30 54 10 1
1 2010 7 1 54 10 1
1 2010 7 2 54 10 1
1 2010 7 3 54 10 1
1 2010 7 4 54 10 1
1 2010 7 5 54 10 1
1 2010 7 6 54 10 1
1 2010 7 7 54 10 1
1 2010 7 8 54 10 1
1 2010 7 9 54 10 1
1 2010 7 10 54 10 1
1 2010 7 12 54 10 1
1 2010 7 13 54 10 1
1 2010 7 14 54 10 1
1 2010 7 15 54 10 1
1 2010 7 16 54 10 1
1 2010 7 17 54 10 1
1 2010 7 18 54 10 1
1 2010 7 19 54 10 1
1 2010 7 20 54 10 1
1 2010 7 21 54 10 1
1 2010 7 22 54 10 1
1 2010 7 23 54 10 1
1 2010 7 24 54 10 1
1 2010 7 25 54 10 1
1 2010 7 26 54 10 1
1 2010 7 27 54 10 1
1 2010 7 28 54 10 1
1 2010 7 29 54 10 1
1 2010 7 30 54 10 1
1 2010 7 31 54 10 1
1 2010 8 1 54 10 1
1 2010 8 2 54 10 1
1 2010 8 3 54 10 1
1 2010 8 4 54 10 1
1 2010 8 5 54 10 1
1 2010 8 6 54 10 1
1 2010 8 7 54 10 1
1 2010 8 8 54 10 1
1 2010 8 9 54 10 1
1 2010 8 10 54 10 1
1 2010 8 11 54 10 1
1 2010 8 12 54 10 1
1 2010 8 13 54 10 1
1 2010 8 14 54 10 1
1 2010 8 15 54 10 1
1 2010 8 16 54 10 1
1 2010 8 17 54 10 1
1 2010 8 18 54 10 1
1 2010 8 19 54 10 1
1 2010 8 20 54 10 1
1 2010 8 21 54 10 1
1 2010 8 22 54 10 1
1 2010 8 23 54 10 1
1 2010 8 24 54 10 1
1 2010 8 25 54 10 1
1 2010 8 26 54 10 1
1 2010 9 1 54 10 1
1 2010 9 2 54 10 1
1 2010 9 3 54 10 1
1 2010 9 4 54 10 1
1 2010 9 5 54 10 1
1 2010 9 6 54 10 1
1 2010 9 7 54 10 1
1 2010 9 8 54 10 1
1 2010 9 9 54 10 1
1 2010 9 10 54 10 1
1 2010 9 11 54 10 1
1 2010 9 12 54 10 1
1 2010 9 13 54 10 1
1 2010 9 14 54 10 1
1 2010 9 15 54 10 1
1 2010 9 16 54 10 1
1 2010 9 17 54 10 1
1 2010 9 18 54 10 1
1 2010 9 19 54 10 1
1 2010 9 20 54 10 1
1 2010 9 21 54 10 1
1 2010 9 22 54 10 1
1 2010 9 23 54 10 1
1 2010 9 24 54 10 1
1 2010 9 25 54 10 1
1 2010 9 26 54 10 1
1 2010 9 27 54 10 1
1 2010 9 28 54 10 1
1 2010 9 29 54 10 1
1 2010 9 30 54 10 1
1 2010 10 1 54 10 1
1 2010 10 2 54 10 1
1 2010 10 3 54 10 1
1 2010 10 4 54 10 1
1 2010 10 5 54 10 1
1 2010 10 6 54 10 1
1 2010 10 7 54 10 1
1 2010 10 8 54 10 1
1 2010 10 9 54 10 1
1 2010 10 10 54 10 1
1 2010 10 11 54 10 1
1 2010 10 12 54 10 1
1 2010 10 13 54 10 1
1 2010 10 14 54 10 1
1 2010 10 15 54 10 1
1 2010 10 16 54 10 1
1 2010 10 17 54 10 1
1 2010 10 18 54 10 1
1 2010 10 19 54 10 1
1 2010 10 20 54 10 1
1 2010 10 21 54 10 1
1 2010 10 22 54 10 1
1 2010 10 23 54 10 1
1 2010 10 24 54 10 1
1 2010 10 25 54 10 1
1 2010 10 26 54 10 1
1 2010 10 27 54 10 1
1 2010 10 28 54 10 1
1 2010 10 29 54 10 1
1 2010 10 30 54 10 1
1 2010 10 31 54 10 1
1 2010 11 1 54 10 1
1 2010 11 2 54 10 1
1 2010 11 3 54 10 1
1 2010 11 4 54 10 1
1 2010 11 5 54 10 1
1 2010 11 7 54 10 1
1 2010 11 8 54 10 1
1 2010 11 9 54 10 1
1 2010 11 10 54 10 1
1 2010 11 11 54 10 1
1 2010 11 12 54 10 1
1 2010 11 13 54 10 1
1 2010 11 14 54 10 1
1 2010 11 15 54 10 1
1 2010 11 16 54 10 1
1 2010 11 17 54 10 1
1 2010 11 18 54 10 1
1 2010 11 19 54 10 1
1 2010 11 20 54 10 1
1 2010 11 21 54 10 1
1 2010 11 22 54 10 1
1 2010 11 23 54 10 1
1 2010 11 24 54 10 1
1 2010 11 25 54 10 1
1 2010 11 26 54 10 1
1 2010 11 27 54 10 1
1 2010 11 28 54 10 1
1 2010 11 29 54 10 1
1 2010 11 30 54 10 1
1 2010 12 1 54 10 1
1 2010 12 2 54 10 1
1 2010 12 3 54 10 1
1 2010 12 4 54 10 1
1 2010 12 5 54 10 1
1 2010 12 6 54 10 1
1 2010 12 7 54 10 1
1 2010 12 8 54 10 1
1 2010 12 9 54 10 1
1 2010 12 10 54 10 1
1 2010 12 12 54 10 1
1 2010 12 15 54 10 1
1 2010 12 16 54 10 1
1 2010 12 17 54 10 1
1 2010 12 18 54 10 1
1 2010 12 19 54 10 1
1 2010 12 20 54 10 1
1 2010 12 21 54 10 1
1 2010 12 22 54 10 1
1 2010 12 23 54 10 1
1 2010 12 24 54 10 1
1 2010 12 25 54 10 1
1 2010 12 26 54 10 1
1 2010 12 27 54 10 1
1 2010 12 28 54 10 1
1 2010 12 29 54 10 1
1 2010 12 30 54 10 1
1 2010 12 31 54 10 1
;
Run;
Data temp ;
  Set Have ;
  if _55_dummy eq 0 then do;output;stop;end;
Run;
data bef_3months aft_12months;
 set temp;
 d=mdy(month,1,year);
 do i=intnx('month',d,-3) to d-1;
  output bef_3months;
 end;
 do i=intnx('month',d,1) to intnx('month',d,12,'e');
  output aft_12months;
 end;
 format i date9.;
 keep id i;
run;
data want; 
if _n_ eq 1 then do;
 if 0 then set bef_3months;
 declare hash ha1(dataset:'bef_3months');
  ha1.definekey(all:'y');
  ha1.definedone();

 if 0 then set aft_12months;
 declare hash ha2(dataset:'aft_12months');
  ha2.definekey(all:'y');
  ha2.definedone();
end;
 set have;
 i=mdy(month,day,year);
bef_3months=ifn(ha1.check()=0,0,1);
aft_12months=ifn(ha2.check()=0,0,1);
drop i;
run;


Xia Keshan

Contributor
Posts: 30

Re: Creating time specific dummy variables

Hi Xia Keshan,

Your code works perfect! thanks, i have a small correction to make, i want the birthday month itself to be coded as 'aft_12months' instead of 'bef_3months' . So before the birth day mont t-3 months (no including the bday month) needs to be codded '0' . The birthday month and 11 consective months needs to be coded as '0' for the 'aft_12months' variable. Can you tell em what to change in the code for that to happen?

-jessica

Contributor
Posts: 30

Re: Creating time specific dummy variables

Hi Xia Keshan,


One more thing i notice is that for individuals who are already 55 years old the dummy is misplaced, for example the driver ID '1' is already 55, so i need the aft_12months' to be zero before the 10th month of year 2009. This individual has already crossed 55 years of age in the last year so 'bef_3 months' will always be '1' for this individual. So your code probably works fine for individuals aged 53 and 54 not 55,56. It would really help me if you tell me how to change the code for this, i learnt a lot how to code from you, thank you very much! Smiley Happy


-jessica

Solution
‎11-04-2014 06:41 AM
Super User
Posts: 9,856

Re: Creating time specific dummy variables

Hi. My code only are only worked for your data i.e. 54 . How do I know what to do with 55 56 ?

Post your new data and new desired output .

Data temp ;
  Set Have ;
  if _55_dummy eq 0 then do;output;stop;end;
Run;
data bef_3months aft_12months;
 set temp;
 d=mdy(month,1,year);
 do i=intnx('month',d,-3) to d-1;
  output bef_3months;
 end;
 do i=d to intnx('month',d,11,'e');
  output aft_12months;
 end;
 format i date9.;
 keep id i;
run;
data want; 
if _n_ eq 1 then do;
 if 0 then set bef_3months;
 declare hash ha1(dataset:'bef_3months');
  ha1.definekey(all:'y');
  ha1.definedone();

 if 0 then set aft_12months;
 declare hash ha2(dataset:'aft_12months');
  ha2.definekey(all:'y');
  ha2.definedone();
end;
 set have;
 i=mdy(month,day,year);
bef_3months=ifn(ha1.check()=0,0,1);
aft_12months=ifn(ha2.check()=0,0,1);
drop i;
run;

Xia Keshan

Contributor
Posts: 30

Re: Creating time specific dummy variables

Thank you for your help, i figured out the changes i had to make in the code for it to work !

jessica

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 361 views
  • 6 likes
  • 3 in conversation