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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 5 replies
  • 1061 views
  • 0 likes
  • 2 in conversation