user3042610
user3042610

Reputation: 13

create categorical variable in sas based upon date

I want to create a categorical variable based upon date and input the following code.

data temppricedata;
    set SASHELP.PRICEDATA;
    date_group='';

    IF (date>='MAR2002'd) THEN
        date_group='new';

    IF (date<'MAR2002'd) THEN
        date_group='old';
run;

However I got error like

    ERROR: Invalid date/time/datetime constant 'MAR2002'd.
    ERROR 77-185: Invalid number conversion on 'MAR2002'd.

I am sure the format follows sas date format which is MONYY. I do not know how to correct this.

Upvotes: 1

Views: 280

Answers (1)

Christos Avrilionis
Christos Avrilionis

Reputation: 412

As @Jeff mentioned, the correct way for specifying SAS date constants is DDMONYY or DDMONYYYY.

 data temppricedata;
        set SASHELP.PRICEDATA;
        length date_group $3.;
        IF date >= '01MAR2002'd THEN date_group='new';
        ELSE IF date <  '01MAR2002'd THEN date_group='old';
    run;

Upvotes: 2

Related Questions