BookmarkSubscribeRSS Feed
KC_16
Fluorite | Level 6

Hi, 

 

I have a CSV file that I need to import into SAS but the issue I have is around 2 date variables (Date_Set and Date_Out) within the CSV as they are both formatted as: 

 

26/07/2017 10:16:00

 

I need a step within my PROC IMPORT to import all the data but the 2 date variables (Date_Set and Date_Out), I need these formatted as a shorthand date only and for the time element to be removed (ddmmyyyy).

 

I have looked through the forum and struggling to find a resolution, any idea how to resolve please?

 

Thanks

4 REPLIES 4
Kurt_Bremser
Super User

proc import does not allow individual coding, so you either need to write a follow-up step for correction, or write a proper data step in the first place.

Take the code created by proc import from the log and adapt/optimize it to your needs. You find that code in the log.

How you proceed depends on what you find there.

For more detailed help, post a few lines of the csv (use the {I} button).

KC_16
Fluorite | Level 6

I have tried to create a data step but doesn't seem to work, what is it that I am doing wrong please?

 

proc sql;
create table work.test as
select Date_In format ddmmyy10. as test_date
from work.YT_uPDATED;
quit;

Kurt_Bremser
Super User

First of all: this I NOT a data step, this is the SQL procedure.

Second: since you do not use a function to convert the type, the variable stays the same. Trying to attach a numeric format to a character variable won't work.

As I already said, if you're unsure what to do, post a few lines of the infile, using the {I} button.

ballardw
Super User

@KC_16 wrote:

I need a step within my PROC IMPORT to import all the data but the 2 date variables (Date_Set and Date_Out), I need these formatted as a shorthand date only and for the time element to be removed (ddmmyyyy).

 


When you run Proc Import for a CSV, or other text type file, the LOG will have the data step code generated. You can copy that code from the LOG, Paste it into the Editor (save), and modify the generate code such as setting nicer variable names or the INFORMAT used to read the variables and the FORMAT to display the values. The format you show would be DATE9. and it looks like an INFORMAT of ddmmyy10. should work to read the values as desired.

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