BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
KevinC_
Fluorite | Level 6

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 Smiley Happy

Thank you !

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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 ;

View solution in original post

5 REPLIES 5
data_null__
Jade | Level 19

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.

Tom
Super User Tom
Super User

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;

KevinC_
Fluorite | Level 6

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!

Tom
Super User Tom
Super User

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 ;

KevinC_
Fluorite | Level 6

Thank you, Tom, for your input!  That worked beautifully.

I really appreciate it Smiley Happy

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 846 views
  • 1 like
  • 3 in conversation