Date: Tue, 30 Mar 2004 11:15:23 -0500
Reply-To: Gerhard Hellriegel <ghellrieg@T-ONLINE.DE>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Gerhard Hellriegel <ghellrieg@T-ONLINE.DE>
Subject: Re: Alternative methods to create a month variable
wouldn't it be easier to cut the first 4 chars of TRANS_DT and add a "20" in
front of that?
TRANS_MO="20"!!substr(TRANS_DT,1,4);
??
On Tue, 30 Mar 2004 11:03:38 -0500, Lu Liu <Lu.Liu@TALBOTS.COM> wrote:
>Hi,
>
>I am creating a transaction month variable (TRANS_MO) from transaction date
>(TRANS_DT). Please note both variables are not in DATE but STRING format.
>Since there are 1 1/2 years data, I need to do the IF/ELSE IF statement 18
>times. I just wonder whether there is a better way to code this.
>
>
>DATA ALLTRANS;
> SET ALLTRANS;
> LENGTH TRANS_MO $6;
> IF TRANS_DT >= '021001' AND TRANS_DT <= '021031'
> THEN TRANS_MO = '200210';
> ELSE IF TRANS_DT >= '021101' AND TRANS_DT <= '021130'
> THEN TRANS_MO = '200211';
> ELSE IF TRANS_DT >= '021201' AND TRANS_DT <= '021231'
> THEN TRANS_MO = '200212';
> ELSE IF TRANS_DT >= '030101' AND TRANS_DT <= '030131'
> THEN TRANS_MO = '200301';
> ELSE IF TRANS_DT >= '030201' AND TRANS_DT <= '030228'
> THEN TRANS_MO = '200302';
> ELSE IF TRANS_DT >= '030301' AND TRANS_DT <= '030331'
> THEN TRANS_MO = '200303';
> ELSE IF TRANS_DT >= '030401' AND TRANS_DT <= '030430'
> THEN TRANS_MO = '200304';
>
>(and more till TRANS_MO = '200403')
>
>Thank you very much for your suggestions.
>
>Lu
|