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.
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.
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.
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
For SAS newbies, this video is a great way to get started. James Harroun walks through the process using SAS Studio for SAS OnDemand for Academics, but the same steps apply to any analytics project.
Find more tutorials on the SAS Users YouTube channel.