BookmarkSubscribeRSS Feed
wtien196838
Quartz | Level 8

Dear SAS user community,

 

 My user passed me an Excel report which has columns of data.

For example, one cell of a column has 82.5%  (real value is 82.4678901235%).

I extract from database to get the value of that cell which is exactly 82.4678901235.

 

When I use sas proc compare, the result is mismatched due to 82.5 vs 82.4678901235.

 

Would you show me a solution to this issue ?

 

PS: if I changed  all values of  excel report format to real values, the proc compare created a matched result report.

 

Thanks in advance.

 

William

 

11 REPLIES 11
ballardw
Super User

I'm not sure I quite follow. Did you import the data into SAS from Excel or some other database, or both?

 

Are you saying the value of 82.4678901235 did or did not appear in the SAS data set? And from which source(see previous question).

 

If you imported data into SAS from Excel describe what method you used. Ditto if reading from another database.

If is possible that the displayed value from Excel is what SAS received depending upon the method used.

 

wtien196838
Quartz | Level 8

I read a range of cells in each excel worksheet. I use DDE to read the value of each cell. Use informat to code each variable.

 

I also extract data from same user oracle database to compare. 

 

In short, user data and my data are the same. Only user present data in excel format is differ to the real value (rounding issue).

 

Is what you see (values in the excel cell) if what you get (rounding number) in reading excel cells into sas datasset ?

 

Example: real value is 82.4678901235, excel format 82.5 and sas read in 82.5000000000 (informat 13.10).

 

My question is how can I read in from excel the real value so that the proc compare user data (read from excel) and my data (read from oracle database) MATCHING ?

 

Reeza
Super User

Please post the DDE code you used to read in the data.

 

Did you correctly specify your informat? In this case you may want to try BEST32. as an informat to read the file correctly.

 

Kurt_Bremser
Super User

This is because Excel is not a sensible transfer medium and the internal Excel file format is not a suitable format for data transfer.

If someone wants to send you test data from a database query, they should unload that into a csv or fixed column file and send you that.

As long as you use Excel as the medium, you will have a constant PITA.

wtien196838
Quartz | Level 8

/* Open Excel file */

PROC FORMAT;
INVALUE TPERC
'N/A' = .
'-' = 999
'#VALUE!' = 999
'#DIV/0!' = 999
other =[17.10]
;

Filename inputf DDE "excel|tabname r10c5:r20c6 notab lrecl=32000; /* sample 2 columns */

Data test ;
infile inputf dlm='09'x DSD Missover PAD;
informat
description $100
quarter_per TPERC
;
run;
---------------------------------------
Excel report:
Location      Qtr_percent
East region  82.5 % (excel format decimal = 1) or 82.4678901235% (format decimal=10)
.... .....

I need to verify the correctness of this report. SAS pull from database the real value
82.4678901235 but sas read in the excel value 82.5000000000.
AS a result, proc compare showed mismatch on the cell.
I CAN NOT modify the user report, change all numbers format to decimal=10. If this is the case,
proc compare showed MATCHING.

Reeza
Super User

Is that your full code? Where's the input statement?

wtien196838
Quartz | Level 8

sorry the code :

informat
description $100
quarter_per TPERC
;

 

should be read

input
description $100
quarter_per TPERC
;

Reeza
Super User

So you don't have an informat specified for your numeric variable. Try using best32. and seeing your results. As I indicated earlier...

 

informat
description $100
quarter_per TPERC best32.
;

wtien196838
Quartz | Level 8

Proc format assigned the value 17.10  (in TPERC) when sas read in the excel cell value.

As a result, the value sas read in is 82.5000000000 which is corresponding to the display cell value 82.5.

While the actual value is 82.4678901235 if we change the format on excel (decimal=10).

The above code is a part of the full program. The program  contains sql to connect database to extract data.

Proc compare to compare two sas datasets which are read in the data from excel report and from database.

FreelanceReinh
Jade | Level 19

Hello William,

 

I think, the problem is that generally formatted values are sent through the DDE connection (SAS-formatted values to Excel and Excel-formatted values to SAS). So, the solution should be to let SAS instruct Excel (via DDE) to show all decimals in the relevant cells and only then read the numbers. Please refer to section 5 ("Changing Cell Formats") on page 4 of this paper for a short data _null_ step to accomplish this.

Reeza
Super User

@wtien196838 Just to clarify, when you ran with Best32 informat it did not work?

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 11 replies
  • 2180 views
  • 1 like
  • 5 in conversation