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
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:
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.
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
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
;
I'm using proc import and it seems that format is not supported
It's not necessary to use proc import on CSV files; much better to write the data step yourself.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.