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-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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