Okay. Gene and Jim were both kind enough to take a stab. Gene - your
code was a much trimmer version of what I was doing before. Now I need some help in figuring out the reason for my problem. Here is the code I'm using along with some sample data. IF the yr_pd_wk falls between effstart1 and end1, it gives me the correct validsource. If it falls between start2 - 4 and end2-4, it gives me a system missing value for the valid source.?? I'm beyond frustrated. Can anyone tell me what I'm doing wrong here? DATA LIST /YR_PD_WK 1-9 loc_cd 10 prod 13 (A) EFFSTART1 16-23 EFFSTART2 25-32 EFFSTART3 34-41 EFFSTART4 45-52 EFFEND1 61-68 EFFEND2 70-77 EFFEND3 79-86 EFFEND4 89-96 SOURCE_LOC_CD1 105-107 SOURCE_LOC_CD2 109-111 SOURCE_LOC_CD3 112-114 SOURCE_LOC_CD4 116-118. BEGIN DATA 2005071 1 A 2005011 2005064 2005091 . 2005064 2005091 9999124 . 5 13 5 . 2005072 1 A 2005011 2005064 2005091 . 2005064 2005091 9999124 . 5 13 5 . 2005073 1 A 2005011 2005064 2005091 . 2005064 2005091 9999124 . 5 13 5 . 2005074 1 A 2005011 2005064 2005091 . 2005064 2005091 9999124 . 5 13 5 . 2005081 1 A 2005011 2005064 2005091 . 2005064 2005091 9999124 . 5 13 5 . 2005082 1 A 2005011 2005064 2005091 . 2005064 2005091 9999124 . 5 13 5 . 2005083 1 A 2005011 2005064 2005091 . 2005064 2005091 9999124 . 5 13 5 . 2005071 1 A 2005011 2005064 2005071 2005072 2005064 2005071 2005072 2005073 13 13 13 13 2005072 1 A 2005011 2005064 2005071 2005072 2005064 2005071 2005072 2005073 13 13 13 13 2005071 1 B 2005011 2006103 . . 2006103 9999134 . . 5 13 . . 2005072 1 B 2005011 2006103 . . 2006103 9999134 . . 5 13 . . 2005073 1 B 2005011 2006103 . . 2006103 9999134 . . 5 13 . . 2005074 1 B 2005011 2006103 . . 2006103 9999134 . . 5 13 . . END DATA. Vector start=effstart1 to effstart4/ end=effend1 to effend4/ source=source_loc_cd1 to source_loc_cd4. Loop #i=1 to 4. + do if (start(#i) le yr_pd_wk and end(#i)>yr_pd_wk). + compute validsource=source(#i). + else. + break. + end if. End loop. execute. Debbie Butler SCP Modeling Analyst Frito Lay Operations 972.334.3934 |
At 04:31 PM 10/31/2006, Butler, Deborah {FLNA} wrote:
Well, stabbing - >IF the yr_pd_wk falls between effstart1 and end1, it gives me the >correct validsource. If it falls between start2 - 4 and end2-4, it >gives me a system missing value for the valid source.?? I'm beyond >frustrated. [...] >Loop #i=1 to 4. >+ do if (start(#i) le yr_pd_wk and end(#i)>yr_pd_wk). >+ compute validsource=source(#i). >+ else. >+ break. >+ end if. >End loop. Well, on the first loop pass, if the DO IF condition is satisfied, you get the right answer, as you've seen. But if it's not, the ELSE clause is executed, the loop terminates, and no other check is done. Answer, SYSMIS. I think you want this, or something similar: Loop #i=1 to 4. + do if (start(#i) le yr_pd_wk and end(#i)>yr_pd_wk). + compute validsource=source(#i). + break. + end if. End loop. |
In reply to this post by Butler, Deborah {FLNA}
Deborah,
I think you should replace + do if (start(#i) le yr_pd_wk and end(#i)>yr_pd_wk). + compute validsource=source(#i). + else. + break. + end if. With just this. I tried to be clever and didn't work the loop logic through correctly. + do if (start(i) le yr_pd_wk and end(i)>yr_pd_wk). + compute validsource=source(i). + end if. Also, given how your 'dates' are structured, you don't need to ever look at the end dates. The start dates have all the information except for the accounting for the last date. Gene Maguin |
Free forum by Nabble | Edit this page |