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;
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";
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.
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;`
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";
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!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.