From: machelle on 19 May 2010 02:17 Hello: I've just noticed something which to me is puzzling.Since the underscore character is a legal character for variables names, I use it often. I've never had any issues before this week when some code I was using stopped working for no explainable reason. /*This code works. The variables are updated appropriately*/ proc sort data=b; by id time; run; data a; set b; if first.id then do; k1i0=1; k2i0=1; k1iw=1; k2iw=1; end; retain k1i0 k2i0 k1iw k2iw; k2i0=k2i0*punci0; k2iw=k2iw*punciw; if Excl_Stop=0 and (visit lt Excl_Stop_vis) then do; /*Not yet stopped*/ k1i0=k1i0*pExcli0; k1iw=k1iw*pExcliw; end; else if ( Excl_Stop=1) and ( Excl_Stop_vis=visit) then do; / *Stopped this visit*/ k1i0=k1i0*(1-pExcli0); k1iw=k1iw*(1-pExcliw); end; else do; / *Stopped previously*/ k1i0=k1i0; k1iw=k1iw; end; Run; /*This code, on the other hand, does NOT WORK!*/ /*The only thing that has changed here are the variable names which now include underscores*/ /*in place of the letter i */ proc sort data=b; by id time; run; data a; set b; if first.id then do; k1_0=1; k2_0=1; k1_w=1; k2_w=1; end; retain k1_0 k2_0 k1_w k2_w; k2_0=k2_0*punc_0; k2_w=k2_w*punc_w; if Excl_Stop=0 and (visit lt Excl_Stop_vis) then do; /*Not yet stopped*/ k1_0=k1_0*pExcl_0; k1_w=k1_w*pExcl_w; end; else if ( Excl_Stop =1) and ( Excl_Stop_vis=visit) then do; /*Stopped this visit*/ k1_0=k1_0*(1-pExcl_0); k1_w=k1_w*(1-pExcl_w); end; else do; / *Stopped previously*/ k1_0=k1_0; k1_w=k1_w; end; I've solved my problem and everything runs, but why is it that the second set of code produces completely different results? I've experimented with other characters other than 'i' and it's only the underscore that seems to be causing the problem. Can someone please explain why? For something that ruined a week of my life, I'd at least like an explanation lol :) thanks, Machelle
From: Arthur Tabachneck on 19 May 2010 08:31 Machelle, Can you provide a sample data step that creates a sample file b which demonstrates the problem? Art ---------------- On May 19, 2:17 am, machelle <machellewilche...(a)gmail.com> wrote: > Hello: > > I've just noticed something which to me is puzzling.Since the > underscore character is a legal character for variables names, I use > it often. I've never had any issues before this week when some code I > was using stopped working for no explainable reason. > > /*This code works. The variables are updated appropriately*/ > > proc sort data=b; by id time; run; > > data a; > set b; > > if first.id then do; > > k1i0=1; k2i0=1; k1iw=1; k2iw=1; > end; > > retain k1i0 k2i0 k1iw k2iw; > > k2i0=k2i0*punci0; > k2iw=k2iw*punciw; > > if Excl_Stop=0 and (visit lt Excl_Stop_vis) then do; /*Not yet > stopped*/ > > k1i0=k1i0*pExcli0; > k1iw=k1iw*pExcliw; end; > > else if ( Excl_Stop=1) and ( Excl_Stop_vis=visit) then do; / > *Stopped this visit*/ > > k1i0=k1i0*(1-pExcli0); > k1iw=k1iw*(1-pExcliw); end; > > else > do; / > *Stopped previously*/ > k1i0=k1i0; > k1iw=k1iw; end; > Run; > > /*This code, on the other hand, does NOT WORK!*/ > /*The only thing that has changed here are the variable names which > now include underscores*/ > /*in place of the letter i */ > > proc sort data=b; by id time; run; > data a; > set b; > > if first.id then do; > > k1_0=1; k2_0=1; k1_w=1; k2_w=1; > end; > > retain k1_0 k2_0 k1_w k2_w; > > k2_0=k2_0*punc_0; > k2_w=k2_w*punc_w; > > if Excl_Stop=0 and (visit lt Excl_Stop_vis) then do; /*Not yet > stopped*/ > k1_0=k1_0*pExcl_0; > k1_w=k1_w*pExcl_w; end; > > else if ( Excl_Stop =1) and ( Excl_Stop_vis=visit) then do; /*Stopped > this visit*/ > k1_0=k1_0*(1-pExcl_0); > k1_w=k1_w*(1-pExcl_w); end; > > else > do; / > *Stopped previously*/ > k1_0=k1_0; > k1_w=k1_w; end; > > I've solved my problem and everything runs, but why is it that the > second set of code produces completely different results? I've > experimented with other characters other than 'i' and it's only the > underscore that seems to be causing the problem. > > Can someone please explain why? For something that ruined a week of my > life, I'd at least like an explanation lol :) > > thanks, > > Machelle
From: FPAStatman on 19 May 2010 10:36 Can you show the error that you are getting? The only thing I see is that you are missing a by statement in your data a. I don't know how your fix worked when you use a first.id without a by id. data a; set b; if first.id then do; k1_0=1; k2_0=1; k1_w=1; k2_w=1; end; doesn't give the inital values of 1, as first.id is unitialized. data a; set b; by id; if first.id then do; k1_0=1; k2_0=1; k1_w=1; k2_w=1; end; works for me. I don't get a problem with the underscores. Art is correct, it would be very helpful to have a dataset.
From: tanwan on 20 May 2010 11:56 data aha (keep=under_score); retain under_score 99.9; set sashelp.class; proc print;run;
|
Pages: 1 Prev: Divide the data set into four groups Next: PAY PER CLICK |