BookmarkSubscribeRSS Feed
moseland
Fluorite | Level 6

 

I am trying to understand how to use formats and informats to correctly import data from .csv into SAS. I have a practice csv that looks to have been created with SAS in the past. I'm trying to determine how to import all of the columns that contain dates so they maintain the DATETIME19 format they were originally created with. The dates appear exactly like this in the csv: 5/25/2014 8:30

 

 

proc import datafile="C:\Users\pc\Documents\SASPractice\chop\visit.csv"
dbms=csv
out=chop.visit  replace;
guessingrows=max;
run;

 

The code above successfully imports the csv and creates a sas datafile. I'm somewhat familiar with SQL, in that you can format each column individually as they come in. I'm sure there's a method to maintain the format of all columns that are imported but am unsure how to build. 

3 REPLIES 3
Tom
Super User Tom
Super User

If you want to have control over how variables are defined when reading a text file then write your own data step. CSV files are easy to read.

 

But I don't understand what your question is.

First DATETIME is a format for a DATETIME value, not for a DATE value.  Second your example of how the text looks in the CSV is not in the DATETIME format but some other format.  

 

Are you asking whether SAS has a format that will display datetime values as strings that look like this:

MM/DD/YYYY HH:SS

I don't think it does, but you could create your own using PICTURE statement in PROC FORMAT.

Panagiotis
SAS Employee

After you import you could change the format using PROC DATASETS.

 

Not sure, but this format might work: MDYAMPM.

 

You can try something like this:

 

proc datasets lib=work /*<--library*/
              memtype=data;
	modify table; /*<--table to modify*/
    attrib colummn1 /*<--Column to format*/ format=mdyampm. /*<--apply new format*/; 
quit; 

It uses AM/PM. Not sure if that's an issue. Let me know.

 

 

 

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
LIBNAME 101

Follow along as SAS technical trainer Dominique Weatherspoon expertly answers all your questions about SAS Libraries.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 1579 views
  • 1 like
  • 4 in conversation