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
PROC Star

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.

 

Check out the Boston Area SAS Users Group (BASUG) video archives: https://www.basug.org/videos.
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 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

From SAS Users blog
Want more? Visit our blog for more articles like these.
5 Steps to Your First Analytics Project Using SAS

For SAS newbies, this video is a great way to get started. James Harroun walks through the process using SAS Studio for SAS OnDemand for Academics, but the same steps apply to any analytics project.

Find more tutorials on the SAS Users YouTube channel.

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