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

    

DATA B1.V2;
SET B1.V4;
KEEP REG_ID BUS  GEN  REG_DATE ;
WHERE BUS IN ('VOLVO','BENZ','ASHOK')
AND REG_DATE between 01/10/2006 and 31/10/2007;
RUN;   

 

In this code i got the result but date format not changed.

my result of reg date format i mentioned below.

So how can i covert character to date format.


Capture1.0.PNG

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

The code that you show should do nothing but throw errors as the "between" values are invalid. If the variable is to be compared to a data literal then the value must appear in one of the DATEw. formats, in quotes and followed by a D, like date9. <=> ' 31OCT2007'd. If the value is character it would require quotes and may not make much sense in terms of "between" because of the way character values are compared.

 

Also the values you show are almost certainly Excel date values, not SAS dates as a numeric value of 39153 is 13Mar2067. So you may have to step back to how you brought the data into SAS or search this forum for the many questions about Excel date conversions.

 

To have numeric value display as a human recognizable date you apply a format to the variable such as

Format Reg_date date9.;
/*or */
Format Reg_date ddmmyy10.;
/* example*/
proc print data=B1.V2;
format Reg_date date9.;
run;

If assigned in a data step or using the Proc Datasets to modify a data sets variable properties the format becomes the default. Otherwise you use the format of interest. SAS provides literally dozens of date, datetime and time formats plus you can make custom formats with Proc Format if one of the standard SAS supplied formats doesn't work.

You really want the numeric version with a format as that is what is needed for any sort of manipulation, such as selecting ranges of values, determining number of intervals between values and such.

 

https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/... has a PDF with much information about dates.

View solution in original post

2 REPLIES 2
ballardw
Super User

The code that you show should do nothing but throw errors as the "between" values are invalid. If the variable is to be compared to a data literal then the value must appear in one of the DATEw. formats, in quotes and followed by a D, like date9. <=> ' 31OCT2007'd. If the value is character it would require quotes and may not make much sense in terms of "between" because of the way character values are compared.

 

Also the values you show are almost certainly Excel date values, not SAS dates as a numeric value of 39153 is 13Mar2067. So you may have to step back to how you brought the data into SAS or search this forum for the many questions about Excel date conversions.

 

To have numeric value display as a human recognizable date you apply a format to the variable such as

Format Reg_date date9.;
/*or */
Format Reg_date ddmmyy10.;
/* example*/
proc print data=B1.V2;
format Reg_date date9.;
run;

If assigned in a data step or using the Proc Datasets to modify a data sets variable properties the format becomes the default. Otherwise you use the format of interest. SAS provides literally dozens of date, datetime and time formats plus you can make custom formats with Proc Format if one of the standard SAS supplied formats doesn't work.

You really want the numeric version with a format as that is what is needed for any sort of manipulation, such as selecting ranges of values, determining number of intervals between values and such.

 

https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/... has a PDF with much information about dates.

Brownisiak69
Fluorite | Level 6
Yes, actually, my data set format has a mistake.
After your reply, I checked my data set and found the error.

Thank you for your help and support.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 692 views
  • 1 like
  • 2 in conversation