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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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