BookmarkSubscribeRSS Feed
joaolopes
Calcite | Level 5

Hi,

 

I have opened a csv file in sas and I have some dates variables in the following format:

19NOV10:00:00:00

25NOV10:10:20:00

26NOV10:13:12:00

etc...

 

How do I remove the time to it so I get:

19NOV10

25NOV10

26NOV10

etc...

 

After that I would like to convert the dates to the following:

19NOV2010

25NOV2010

26NOV2010

etc...

 

How do I do it?

 

Also, let's say that in a further step the date "25NOV10" is not correct and want it to replace with "25NOV11". How do I do this?

 

 

Thanks in advance

 

A

 

 

5 REPLIES 5
Kurt_Bremser
Super User

Please show us the CSV file as is. Open it with a text editor (e.g. Notepad, but do NOT use Excel!), and copy/paste a few lines into a window opened with this button:

Bildschirmfoto 2020-04-07 um 08.32.59.jpg

 

Depending on the data, you may be able to read the date difrectly by using a date informat.

 

Once a datetime has been read into SAS as such, use the DATEPART function to extract the date from it.

joaolopes
Calcite | Level 5

This is an example of some of the rows

 

"id","date"
1,2010-11-19 00:00:00
2,2010-11-25 10:20:00
3,2010-11-26 13:12:00

 

Thanks

Kurt_Bremser
Super User

With data like this, you can easily apply the date informat directly on the text data:

data want;
infile datalines dlm="," firstobs=2;
input id $ date :yymmdd10.;
format date yymmdd10.;
datalines;
"id","date"
1,2010-11-19 00:00:00
2,2010-11-25 10:20:00
3,2010-11-26 13:12:00
;
joaolopes
Calcite | Level 5

I'm using proc import and it seems that format is not supported

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

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
  • 5 replies
  • 577 views
  • 0 likes
  • 2 in conversation