Help using Base SAS procedures

date-remove slash

Reply
Occasional Contributor
Posts: 12

date-remove slash

I need to change the dates in a column from 99/9999 to 999999. How do I remove the slash?
Trusted Advisor
Posts: 2,113

Re: date-remove slash

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.
Contributor
Posts: 33

Re: date-remove slash

> 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.
Occasional Contributor
Posts: 12

Re: date-remove slash

They are in text format.
Regular Contributor
Posts: 165

Re: date-remove slash

Try using compress(var,'/')

Good luck!
Contributor
Posts: 33

Re: date-remove slash

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 ***;
Occasional Contributor
Posts: 12

Re: date-remove slash

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;
Regular Contributor
Posts: 165

Re: date-remove slash

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
Ask a Question
Discussion stats
  • 7 replies
  • 1309 views
  • 0 likes
  • 4 in conversation