Hello everyone,
I am trying to read a csv file. For some reason my SAS code is reading beyond the last row. To be more specific, the input file has 2101 rows, but SAS reads in 2706 rows. Therefore, the last 605 rows are blank. Here is my SAS code:
Data nov1 infile "my_dir\nov1.csv' delimiter = ',' missover DSD lrecl=32767 firstobs=2;
input
col1 col2 col3 ... col31;
run;
The code works for other csv files. Am i missing something obvious here?
I appreciate any input anyone may have
Thank you !
You will have to type the names at least once. I usually just read them from the file and change the delimiters to spaces and past them into the program.
You can save some typing a couple of ways.
1) Put the names into a macro variable.
%let names=transaction_type avg .... last_var ;
input &names ;
if 0=n(of &names) then delete;
2) Use name ranges so you only have to retype the first and last variable name.
if 0=n(of transaction_type -- last_var) then delete ;
Did you get any interesting or unexpected messages in the log?
You may need to specify TERMSTR but without knowing more that is just a guess.
Sounds like your file just has some extra blank lines at the end.
Why not just delete the rows without any non-missing values?
data nov1;
infile "my_dir\nov1.csv' delimiter = ',' missover DSD lrecl=32767 firstobs=2;
input col1 - col31 ;
if 0=n(of col1-col31) then delete;
run;
Thank you data_null and Tom!
Tom,
Your suggestion sounds great. The only problem is the columns are not named 'col1 ... col31). They are named like 'transaction_type', 'avg', 'cust_id',... etc.;
How would I adopt these columns in your suggestion?
Thank you!
You will have to type the names at least once. I usually just read them from the file and change the delimiters to spaces and past them into the program.
You can save some typing a couple of ways.
1) Put the names into a macro variable.
%let names=transaction_type avg .... last_var ;
input &names ;
if 0=n(of &names) then delete;
2) Use name ranges so you only have to retype the first and last variable name.
if 0=n(of transaction_type -- last_var) then delete ;
Thank you, Tom, for your input! That worked beautifully.
I really appreciate it
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.