BookmarkSubscribeRSS Feed
tjonas
Calcite | Level 5
I need to change the dates in a column from 99/9999 to 999999. How do I remove the slash?
7 REPLIES 7
Doc_Duke
Rhodochrosite | Level 12
If they are formatted dates, just change the format. If they are character strings, there are several character functions that will do it; SUBSTR and || is sort of brute force, but will work.
stateworker
Fluorite | Level 6
> If they are formatted dates, just change the format.
> If they are character strings, there are several
> character functions that will do it; SUBSTR and ||
> is sort of brute force, but will work.

Brute Force - Love it.

I have to put in a good word for this book that is well-worn along with my SAS course books I've collected... It's available in the SAS bookstore and other places.

The Essential Guide to SAS Dates and Times
By: Derek Morgan
176 pages
ISBN: 978-1-59047-884-4
Publisher: SAS Press
Copyright Date: June 2006
Description:
Why does SAS use January 1, 1960, as its arbitrary reference date? How do you convert a value such as 27 January 2003 into SAS dates? You'll find the answers to these questions and much more in Derek Morgan's Essential Guide to SAS Dates and Times, which makes it easy to understand how to use and manipulate dates, times, and datetimes in SAS. Novice-to-intermediate users will find the clear, task-focused examples and explanations of formats and functions invaluable; experienced users will appreciate discussions of topics such as intervals and international date and time formats. Included is a bonus "Quick Reference Guide" listing all the formats (with examples) on one handy page.
tjonas
Calcite | Level 5
They are in text format.
RickM
Fluorite | Level 6
Try using compress(var,'/')

Good luck!
stateworker
Fluorite | Level 6
If you decide to brute force it,

format M $2. Y $4.;
M=substr(var, 1,2); *** this will give you the 99 before the slash ***;
Y=substr(var, 4,4); *** this will give you the 9999 after the slash ***;
newdate=(M||Y); *** this will concantenate the two variables to give you 999999 ***;
tjonas
Calcite | Level 5
I'm a new sas user and I've never heard of brute force.

Is this close?

data slash (keep=temp);
set ytd;
format date MMYYN.;
run;
RickM
Fluorite | Level 6
If your date is a character variable then use the compress funtion. If it is a numeric SAS date then use the format.

data _NULL_;
a='05/2011';
b= compress(a,'/');
c=today();
d=c;
format d mmyyn6.;
put a= b= c= d=;
run;

results in :
a=05/2011 b=052011 c=18765 d=052011

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 7 replies
  • 7069 views
  • 0 likes
  • 4 in conversation