how to read the last column of a csv

Reply
Occasional Contributor
Posts: 10

how to read the last column of a csv

Hi,

I have the following code to read a csv:

data brightcovevideo;

retain id videoname views minutes segment50 segment75 segment100;

length videoname $ 255;

infile 'C:\Documents and Settings\gautrj1\Desktop\report\brightcovevideo.csv' 

DSD FIRSTOBS=2 LRECL=10000 termstr=crlf;

input id videoname views minutes segment50 percent4. segment75 percent4. segment100 percent4. ;

format id bestd14.;

run;

the last column of the csv is a percentage and i have the informat set, but the data read into sas does not match up (ie.  37% in row 1 below is 2254 in SAS.  I'm thinking that SAS goe to the end of the line and looks for a comma, but don't know how to account for that in SAS.   Any ideas?  Thanks, John

IDVideo NameViewsViewed MinutesPercentage to 50% MarkPercentage to 75% MarkPercentage of Complete Views
2312832021001Career Framework_MST2200641755%51%37%
2254686068001Access and Permissions-LFD Advisor Registration597186356%52%41%
2197943093001LFG_RPS_V1058079646%39%19%
2020247472001Lincoln Financial® Presents an Annuity Story546365159%53%41%
Super User
Posts: 5,496

Re: how to read the last column of a csv

Posted in reply to jgautreau

It's probably that your informat is PERCENT4, but there are only 3 characters in 37%.  Try adding TRUNCOVER to the end of the INFILE statement.

Good luck.

Respected Advisor
Posts: 3,799

Re: how to read the last column of a csv

Posted in reply to jgautreau

DSD and formatted input (as you have written in your input statement) are incompatible.  Use the colon modified to get proper result

var Smiley Tongueercen4.

Ask a Question
Discussion stats
  • 2 replies
  • 201 views
  • 3 likes
  • 3 in conversation