BookmarkSubscribeRSS Feed
Brownisiak69
Fluorite | Level 6

I need an extra variable as ' environment' with the result after 01/03/2020 as 'pandemic' else 'normal'. I wrote the below mention query.

DATA SSN2.ENVIRONMENT;

SET SSN2.TASK5;

KEEP FULL_NAME CITY STATE PHONE DATE_OF_JOINING COURSE ENVIRONMENT TOOL FEE;

IF DATE_OF_JOINING <= 01/03/2020 THEN ENVIRONMENT='NORMAL';

ELSE ENVIRONMENT= 'PANDAMIC';

RUN;

But i got the error all the result pandemic. kindly recheck and suggest.

3 REPLIES 3
Reeza
Super User

To specify a date constant in SAS it must be in the date9 format, e.g DDMMMYY or '01Mar2020'd

Is pandemic spelled correctly in the code?

 

DATA SSN2.ENVIRONMENT;

SET SSN2.TASK5;

KEEP FULL_NAME CITY STATE PHONE DATE_OF_JOINING COURSE ENVIRONMENT TOOL FEE;

IF DATE_OF_JOINING <= '01Mar2020'd THEN ENVIRONMENT='NORMAL';
ELSE ENVIRONMENT= 'PANDEMIC';

RUN;

@Brownisiak69 wrote:

I need an extra variable as ' environment' with the result after 01/03/2020 as 'pandemic' else 'normal'. I wrote the below mention query.

DATA SSN2.ENVIRONMENT;

SET SSN2.TASK5;

KEEP FULL_NAME CITY STATE PHONE DATE_OF_JOINING COURSE ENVIRONMENT TOOL FEE;

IF DATE_OF_JOINING <= 01/03/2020 THEN ENVIRONMENT='NORMAL';

ELSE ENVIRONMENT= 'PANDAMIC';

RUN;

But i got the error all the result pandemic. kindly recheck and suggest.


 

Quentin
Super User

If date_of_joining is a date variable, you would need to change to:

 

 

IF DATE_OF_JOINING <= "03Jan2020"d THEN ENVIRONMENT='NORMAL';
ELSE ENVIRONMENT= 'PANDAMIC';

"03Jan2020"d is a date literal.  Your current code:

IF DATE_OF_JOINING <= 01/03/2020 THEN ENVIRONMENT='NORMAL';
ELSE ENVIRONMENT= 'PANDAMIC';

will run without error, but SAS will interpret 01/03/2020 as being division.

1    data _null_ ;
2      x=01/03/2020 ;
3      y="03Jan2020"d ;
4      put x= y=;
5    run ;

x=0.0001650165 y=21917

Note if any records have missing values for Date_Of_Joining, this would categorize them as Normal.

 

Brownisiak69
Fluorite | Level 6

 Hi, Quentin

As tried the query provided by you worked successfully, much more thanks for your help and support.