Write and run SAS programs in your web browser

importing data

Reply
New Contributor
Posts: 4

importing data

I am trying to import data from a csv file into SAS studio.  When I run the program, the notes tell me that there were zero observations and two variables.  There are two variables, but there should be 39.  What am I doing wrong?  I have attached my code, as well as a screen shot of my csv file.  Thank you for your help.  

data CitynameSTinSAS;
infile "/folders/myfolders/CitynameSTforSAS.csv" dlm="," firstobs=2;
input Temp Met;
run;

Tim Muhich 


Screen Shot 2016-09-10 at 8.52.34 PM.pngScreen Shot 2016-09-10 at 8.52.34 PM.png
Grand Advisor
Posts: 17,464

Re: importing data

You need to list your variables in the input statement. Since you only lost two variables that's all it reads. 

New Contributor
Posts: 4

Re: importing data

Thank you for replying.  I thought I had listed my variables; I only have two.  It is just not bringing the data along with them.  What am I missing in that statement to bring all of the temperature and metabolism data along with the variable names?  

Thank you again for your time,

Tim

Super User
Posts: 1,256

Re: importing data

Adding the option TRUNCOVER in infile statement, may help:

data
CitynameSTinSAS; infile "/folders/myfolders/CitynameSTforSAS.csv" dlm="," firstobs=2 TRUNCOVER; input Temp Met; run;
New Contributor
Posts: 4

Re: importing data

Maybe there is something wrong with my csv file then.  When I tried your suggestion Shmuel, I got the following message


Screen Shot 2016-09-11 at 9.49.13 AM.png
Super User
Posts: 1,256

Re: importing data

Can you open your CSV file with a text editor and upload a screenshot of it ?

Are you sure that FIRSTOBS should be 2 ?

Grand Advisor
Posts: 17,464

Re: importing data

@timgpp In your first post you included two screenshots of your error message but not a screenshot of your CSV. 

Include either the CSV or at the minimum a screenshot for help. It's likely an easy solution. 

 

Super User
Super User
Posts: 6,383

Re: importing data

Your error message is saying that there 221 bytes, but no records in file past the first line.  Perhaps your data is all on one line?

Try just telling SAS to read the file and show you want is in it. 

 

data _null_;
  infile '/folders/myfolders/CitynamesSTforSAS.csv' ;
  input;
  list;
run;

Then you can look and see what is there.  

Perhaps the data is just all on one line?

data want;
  infile '/folders/myfolders/CitynamesSTforSAS.csv' dsd;
  input Temp Met @@;
run;
New Contributor
Posts: 4

Re: importing data

Thank you all for your help.  You were right.  It was the CSV file.  Only the first line of the Excel sheet saved for some reason ( Thanks Tom for the tip about 221 bytes).  I resaved the file as a CSV and it contained all the data.  Life is good.  

Ask a Question
Discussion stats
  • 8 replies
  • 430 views
  • 0 likes
  • 4 in conversation