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.

 

The Boston Area SAS Users Group is hosting free webinars!
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.
Brownisiak69
Fluorite | Level 6

 Hi, Quentin

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

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 870 views
  • 2 likes
  • 3 in conversation