BookmarkSubscribeRSS Feed
sahoositaram555
Pyrite | Level 9

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%

3 REPLIES 3
Patrick
Opal | Level 21

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;
Kurt_Bremser
Super User

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%)
ChrisNZ
Tourmaline | Level 20

> 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.

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
  • 3 replies
  • 872 views
  • 0 likes
  • 4 in conversation