BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Inp
Obsidian | Level 7 Inp
Obsidian | Level 7

Hi 

I am trying to loading 17 digits length number from sas table to ODS TAGSETS.EXCELXP ( using SAS94) . but it is messing up the last 3 digits of the number. Can any one please let me know the solution to my problem.  Here is my sample coding .

 

DATA TEMP1;
X = 12345678901234567;
RUN;

 

FILENAME TEMP 'C:\TMP\TEST.XLS';

ODS _ALL_ CLOSE;
ODS TAGSETS.EXCELXP FILE=TEMP STYLE=STYLES.HTMLBLUE RS=NONE;
ODS TAGSETS.EXCELXP OPTIONS(SHEET_NAME="MATCH"

EMBEDDED_TITLES='YES'
AUTOFILTER='ALL' AUTOFIT_HEIGHT='YES' MINIMIZE_STYLE='YES'
ABSOLUTE_COLUMN_WIDTH='30'
ORIENTATION='LANDSCAPE' SCALE='75');

RUN;

TITLE 'TESTING AS OF MAY2021';

PROC REPORT DATA=TEMP1 NOWD SPLIT='*' ;
COLUMN X;
DEFINE X / 'ACCOUNT' 
style={tagattr='format:00000000000000000'};
RUN;

ODS _ALL_ CLOSE;
ODS LISTING;

1 ACCEPTED SOLUTION

Accepted Solutions
4 REPLIES 4
Kurt_Bremser
Super User

You run into the limits of numeric precision caused by the finite amount of binary digits used to store decimal numbers. Because of this, SAS (and any software that uses 64 bits to store numbers in floating point format) can "only" handle up to 15 (and for some numbers, 16) decimal digits without loss of precision.

For the field of statistics, this poses no problem.

If that "number" is in fact some kind of code, store it as character.

Inp
Obsidian | Level 7 Inp
Obsidian | Level 7

Thanks very much for your help,

 

Even I changed this X value to  y as charactor  , but it doesn't shows as charactor and truncate as numeric value. Is there any way to change this y to charactor where I can load to  ODS TAGSETS.EXCELXP. Should I have to put any style where it can change as Charactor? . ? If any ,can you please tell how? 

 

 

DATA TEMP1;
length y $16;

X = 12345678901234567;

y=put(x,z16.);

RUN;

 

FILENAME TEMP 'C:\TMP\TEST.XLS';

ODS _ALL_ CLOSE;
ODS TAGSETS.EXCELXP FILE=TEMP STYLE=STYLES.HTMLBLUE RS=NONE;
ODS TAGSETS.EXCELXP OPTIONS(SHEET_NAME="MATCH"

EMBEDDED_TITLES='YES'
AUTOFILTER='ALL' AUTOFIT_HEIGHT='YES' MINIMIZE_STYLE='YES'
ABSOLUTE_COLUMN_WIDTH='30'
ORIENTATION='LANDSCAPE' SCALE='75');

RUN;

TITLE 'TESTING AS OF MAY2021';

PROC REPORT DATA=TEMP1 NOWD SPLIT='*' ;
COLUMN y;
DEFINE y / 'ACCOUNT' format=$16.;

RUN;

ODS _ALL_ CLOSE;
ODS LISTING;`

Kurt_Bremser
Super User

The loss of precision happens here:

X = 12345678901234567;

Anytime you cram such a number into a SAS variable, it happens.

Store it as a string in the first place:

X = "12345678901234567";
Inp
Obsidian | Level 7 Inp
Obsidian | Level 7
Thanks very much . That resolved my problem.

Thanks and Regards,

Inp

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 4 replies
  • 768 views
  • 1 like
  • 2 in conversation