Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Importing an csv file

Status
Not open for further replies.

evaaseow

Programmer
Jan 25, 2007
29
CA
Please help me! this is the last part I need to figure out for this program(crossing fingers)

When I import the csv file there are dates in the format of "ddmmmyy"

What i'm planning on doing is an import of the csv file into dataset that exactly mimics another table. Then to do a merge so that the records in the csv file get appended to the table.

This is what i have so far.

data work.new;
length house $10;
length condo $10;
length start_date ???;

infile "c:\project.csv" dsd missover firstobs=2;
input house $ condo $ start_date???;
run;

Can someone please help me with the ???
 
The datatype of your start_date variable depends on the type that's found on your target table (the one you want to merge with). If it is a SAS date field it will be a numeric variable.
In your length statement you would write the following:
Code:
length start_date 8;

In your input statement for start_date you would do the following
Code:
input house $ condo $ start_date : date11.;

I hope this helps you,
Klaz
 
I really appreciate your help Klaz.

I tried that code you gave me and I receive this error -->

ERROR 48-59: The informat $DATE was not found or could not be loaded.

Any advice?
 
Klaz never mind the previous post, it was a typo that cause the error...still working on it, hopefully it works!
 
Ok, people are making my life miserable.

In the csv file the date appears as ddmmmyy (10Jan07)

In the dataset table the format is DDMMYYYY10.

How should I import this csv file so that these records can be appended to the permanent dataset table?
 
Ok, I finally got things to import and show up properly. My very last question is when importing a csv file that was from an excel spreadsheet originally it currently imports a bunch of blanks lines, is there any way of stopping this from happening?
 
Yep, I generally add a line like this at the end
Code:
  if house = '' then delete;
This deletes any records where house is missing. It's best obviously to pick a field which should always be populated. If the dataset has no such fields, then you need to check all of them:-
Code:
  if house = '' AND condo = '' AND start_date = . then delete;


Chris
Business Analyst, Code Monkey, Data Wrangler.
SAS Guru.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top