BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
amigapomba
Fluorite | Level 6

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!

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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!

 


 

View solution in original post

2 REPLIES 2
Reeza
Super User

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 Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1653 views
  • 0 likes
  • 2 in conversation