hi all,
I imported an xlsx file into university addition using the import snippet. Date is in MM/DD/YYYY format. I assume SAS doesn't know that so I wrote a format statement to clarify. I then tried to create a categorical variable "reg" based on the date. The code I used is as follows:
data sc.date;
set sc2;
format date mmddyy10.;
run;
data sc.change;
set sc.date;
if date < 06/06/2014 then reg = "before";
else reg = "after";
run;
I'm not getting any errors, however all of my observations have been assigned "after", even though many of them have a date prior to 6/6/2014.
Thanks in advance for any help!
SAS is seeing, 06/06/2014 which is 6 divided by 6, divided by 2014.
To specify a date, a specific format has to be used, the date9 format and enclosed in quotes and with a d at the end.
if date < '06Jun2014'd then reg='Before'; else reg = 'After';
Date and time literals:
t -> time -> '08:00't
dt -> datetime
d -> date
@amigapomba wrote:
hi all,
I imported an xlsx file into university addition using the import snippet. Date is in MM/DD/YYYY format. I assume SAS doesn't know that so I wrote a format statement to clarify. I then tried to create a categorical variable "reg" based on the date. The code I used is as follows:
data sc.date;
set sc2;
format date mmddyy10.;
run;
data sc.change;
set sc.date;
if date < 06/06/2014 then reg = "before";
else reg = "after";run;
I'm not getting any errors, however all of my observations have been assigned "after", even though many of them have a date prior to 6/6/2014.
Thanks in advance for any help!
@amigapomba wrote:
hi all,
I imported an xlsx file into university addition using the import snippet. Date is in MM/DD/YYYY format. I assume SAS doesn't know that so I wrote a format statement to clarify. I then tried to create a categorical variable "reg" based on the date. The code I used is as follows:
data sc.date;
set sc2;
format date mmddyy10.;
run;
data sc.change;
set sc.date;
if date < 06/06/2014 then reg = "before";
else reg = "after";run;
I'm not getting any errors, however all of my observations have been assigned "after", even though many of them have a date prior to 6/6/2014.
Thanks in advance for any help!
SAS is seeing, 06/06/2014 which is 6 divided by 6, divided by 2014.
To specify a date, a specific format has to be used, the date9 format and enclosed in quotes and with a d at the end.
if date < '06Jun2014'd then reg='Before'; else reg = 'After';
Date and time literals:
t -> time -> '08:00't
dt -> datetime
d -> date
@amigapomba wrote:
hi all,
I imported an xlsx file into university addition using the import snippet. Date is in MM/DD/YYYY format. I assume SAS doesn't know that so I wrote a format statement to clarify. I then tried to create a categorical variable "reg" based on the date. The code I used is as follows:
data sc.date;
set sc2;
format date mmddyy10.;
run;
data sc.change;
set sc.date;
if date < 06/06/2014 then reg = "before";
else reg = "after";run;
I'm not getting any errors, however all of my observations have been assigned "after", even though many of them have a date prior to 6/6/2014.
Thanks in advance for any help!
@amigapomba wrote:
hi all,
I imported an xlsx file into university addition using the import snippet. Date is in MM/DD/YYYY format. I assume SAS doesn't know that so I wrote a format statement to clarify. I then tried to create a categorical variable "reg" based on the date. The code I used is as follows:
data sc.date;
set sc2;
format date mmddyy10.;
run;
data sc.change;
set sc.date;
if date < 06/06/2014 then reg = "before";
else reg = "after";run;
I'm not getting any errors, however all of my observations have been assigned "after", even though many of them have a date prior to 6/6/2014.
Thanks in advance for any help!
thank you!!
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.