Help using Base SAS procedures

Trouble importing data formatted as percent

Posts: 0

Trouble importing data formatted as percent

I have a .csv file that I'm importing into SAS using the infile statement. There are a few columns that have data formatted as a percent, but the percentages in the raw data don't always show 2 decimal places, so "6.00%" is writen as "6%".

I'm importing the data in an infile datastep so I have the informat set at percent3.2 for those fields. The import runs without any errors, however when I check the SAS data set the percentages without any decimal places are imported incorrectly.

For example:
"6%" gets read as .0006
"6.12%" gets read in correctly as .0612

I need the "6%" to be read in as .06. Any ideas how I can fix this?

Sample of my code:
data work.MyDataset;
%let _EFIERR_ = 0;
infile 'C:\MyFile.csv'
delimiter = ',' MISSOVER DSD lrecl=32767 firstobs=2 ;
informat OldInterestRate percent3.2 ;
informat NewInterestRate percent3.2 ;
format OldInterestRate 10.6 ;
format NewInterestRate 10.6 ;
Super Contributor
Super Contributor
Posts: 3,174

Re: Trouble importing data formatted as percent

Here is a code example to try:

39 data _null_;
40 informat pctval percent.;
41 format pctval percent7.2;
42 input pctval ;
43 putlog _all_;
44 datalines;

pctval=6.22% _ERROR_=0 _N_=1
pctval=6.00% _ERROR_=0 _N_=2
NOTE: DATA statement used
47 run;

Scott Barry
SBBWorks, Inc.
Posts: 0

Re: Trouble importing data formatted as percent

I figured it out...guess I just needed a break from it for awhile. If I change the informat from percent3.2 to percent3. (dropping the 2) it appears to work fine.
Ask a Question
Discussion stats
  • 2 replies
  • 2 in conversation