BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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
-but-
"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 ;
.....
2 REPLIES 2
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.
deleted_user
Not applicable
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.

sas-innovate-2024.png

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.

 

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
  • 2 replies
  • 1675 views
  • 0 likes
  • 2 in conversation