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!

 


 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 1980 views
  • 0 likes
  • 2 in conversation