Alma P
Alma P

Reputation: 13

Reading in character data as numeric

I have a csv file where some of the numerical values are expressed as strings with commas as thousand separator, e.g. "1,513,256" instead of 1513256. What is the simplest way to read the data into SAS

Upvotes: 1

Views: 51

Answers (1)

Tom
Tom

Reputation: 51621

Read the data using the COMMA. informat.

I find that for reading delimited files it works best if you first define the variables. The LENGTH statement is good for this, but you can also use the ATTRIB statement. Make sure to attach any required informats and/or formats. Note that most character and numeric variables to do require either an informat or a format, the defaults work fine. Then write the INPUT statement.

data want ;
  infile 'myfile.csv' dsd truncover firstobs=2;
  length id $10 cost 8;
  informat cost comma.;
  input id cost;
run;

Upvotes: 1

Related Questions