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!

 


 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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