Learning SAS? Welcome to the exclusive online community for all SAS learners.

Problem in importing data from CSV

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 18
Accepted Solution

Problem in importing data from CSV

I m having a csv file of contacts which i want to import, but some of the fields are empty in the table and sas is just taking the next values in table not skipping(keeping them empty). Also it shows a warning sign that "Limit sets by ERROR=option reached" and showing the names column empty in the whole table. What to do?

Also how to import only some of the fields from a csv file?

Attachment

Accepted Solutions
Solution
‎12-26-2014 02:57 PM
Super User
Super User
Posts: 7,060

Re: Problem in importing data from CSV

Because you tried to read the names into a numeric variable. Names are very unlikely to be able read as a number.  If you know that the variable is character you need to define as such.  Without any other information SAS will default any variable you reference as numeric.

View solution in original post


All Replies
Super User
Posts: 19,822

Re: Problem in importing data from CSV

How are you importing the file? Proc Import or a Data Step?

Can you post an example of the file and the code you are using to import?

Occasional Contributor
Posts: 18

Re: Problem in importing data from CSV

data statement.How to do it with proc import?

Occasional Contributor
Posts: 18

Re: Problem in importing data from CSV

Now as i am writing this code by defining the length of Jname, the program doesn't submit. It just gets stuck there...

data p.............s;

  infile '/folders/myfolders/Files/................csv' dlm=',' firstobs=2;

  Length Jname $ 20;

  input Jname HPhone MPhone;

  Markup=3*Hphone-Mphone;

run;

proc print data=p...............s;

run;

Super User
Posts: 19,822

Re: Problem in importing data from CSV

Move the markup line before the input line. Add truncover option to infile statement as well.

Occasional Contributor
Posts: 18

Re: Problem in importing data from CSV

whenever i add the length option the program gets stuck at running......

Occasional Contributor
Posts: 18

Re: Problem in importing data from CSV

nothing happened with truncover.....

Super User
Posts: 19,822

Re: Problem in importing data from CSV

If Tarun's answer doesn't work you'll have to provide a sample of your data.

Occasional Contributor
Posts: 18

Re: Problem in importing data from CSV

the missover method worked well. But the by using the :$20 with jname is making it trunc to a character.

I am attaching a csv file for sample data now.

Frequent Contributor
Posts: 78

Re: Problem in importing data from CSV

increase the length of jname variable to 50 - or 60

data cust_details;

infile "D:\solution\sample.csv" dsd missover dlm = ',';
input Jname:$50.  HPhone:$12. MPhone:$12.;

run;

Occasional Contributor
Posts: 18

Re: Problem in importing data from CSV

Posted in reply to TarunKumar

No i am using this code. But instead of any number or name i m getting only a character in most of the fields. isn't ":$15" only for characters while Hphone and Mphone are numbers.

data p........s;

  infile '/folders/myfolders/Files/p............s.csv' dsd missover dlm=',' firstobs=2;

  input Jname:$50 HPhone:$15 MPhone:$15;

  Markup=3*Hphone-Mphone;

run;

proc print data=p...........s;

run;

Frequent Contributor
Posts: 78

Re: Problem in importing data from CSV

data p........s;

  infile '/folders/myfolders/Files/p............s.csv' dsd missover dlm=',' firstobs=2;

  input Jname:$50 HPhone MPhone;

  Markup=3*Hphone-Mphone;

run;

Occasional Contributor
Posts: 18

Re: Problem in importing data from CSV

Posted in reply to TarunKumar

i did that too but no improvement. i have also attached a sample of my data file in the original post

Frequent Contributor
Posts: 78

Re: Problem in importing data from CSV

Try this you can increase the length of th hphone and mphone.

data cust_details;

infile "D:\Transaction_data\cust_mast.csv" dsd missover dlm = ',';
input Jname:$20.  HPhone:$12. MPhone:$12.;

run;

Super User
Super User
Posts: 7,060

Re: Problem in importing data from CSV

You need to use the DSD option on the INFILE statement to tell SAS to treat consecutive delimiters as meaning there is a missing value. Otherwise it treats them the same as it would multiple spaces in a space delimited list.

data want ;

infile 'sample.csv' dsd truncover firstobs=2;

length Name $40 HomePhone $11 MobilePhone $11 ;

input Name HomePhone MobilePhone ;

run;

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 35 replies
  • 1301 views
  • 8 likes
  • 5 in conversation