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 (BASUG) is hosting our in person SAS Blowout on Oct 18!
This full-day event in Cambridge, Mass features four presenters from SAS, presenting on a range of SAS 9 programming topics. Pre-registration by Oct 15 is required.
Full details and registration info at https://www.basug.org/events.
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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 740 views
  • 2 likes
  • 3 in conversation