Hi all,
I have a numeric column named COL1 with values in a dataset . I would like to apply a character format to it by using proc format. but applying the format it's showing wrong values(looks like junk).
If anyone can help me figuring this problem out, please drop a line .
code i'm using is written below.
data dummy;input COL1; cards;
58
112
6
46
104
158
40
;
run;
proc format library=myf.percent;
value per 58="58/524(11.07%)"
112="112/524(21.37%)"
6="6/524(1.15%)"
46="46/524(8.78%)"
104="104/524(19.85%)"
158="158/524(30.15%)"
40="40/524(7.63%)";
run;
applying format by doing the below step
data temp2;
set temp1; options fmtsearch=(myf.percent);
format col1 percent.;
run;
in the output dataset it shows something like
6E3%
1E4%
600%
5E3%
1E4%
2E4%
4E3%
There are a few things which don't add-up in the code as posted.
You define a format with name per but in the data step you're using percent. Also OPTIONS is a global statement. It doesn't belong into a SAS data or Proc step but needs to be outside of it (on its own; global).
Below code works.
data have;
input COL1;
cards;
58
112
6
46
104
158
40
;
proc format ;
value myformat
58="58/524(11.07%)"
112="112/524(21.37%)"
6="6/524(1.15%)"
46="46/524(8.78%)"
104="104/524(19.85%)"
158="158/524(30.15%)"
40="40/524(7.63%)";
run;
proc print data=have;
format col1 myformat.;
run;
The format you actually use is the SAS built-in PERCENT. format, and since the default length is too short for a value of 58 (which translates to 5800 %), it switches to scientific notation.
You also do not use your example dataset dummy in the final data step.
Using consistent names, the WORK library for formats, the correct format, and proper code formatting, I get this:
data have;
input COL1;
cards;
58
112
6
46
104
158
40
;
proc format;
value per
58="58/524(11.07%)"
112="112/524(21.37%)"
6="6/524(1.15%)"
46="46/524(8.78%)"
104="104/524(19.85%)"
158="158/524(30.15%)"
40="40/524(7.63%)"
;
run;
data want;
set have;
format col1 per.;
run;
Resulting dataset as displayed:
COL1 58/524(11.07%) 112/524(21.37%) 6/524(1.15%) 46/524(8.78%) 104/524(19.85%) 158/524(30.15%) 40/524(7.63%)
> looks like junk
not unlike your code 🙂
Take the time to format your code properly (like your respondents did) I promise you'll save time in the long run as many mistakes will be avoided.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.