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.
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.
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.
Hi, Quentin
As tried the query provided by you worked successfully, much more thanks for your help and support.
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.
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.