BookmarkSubscribeRSS Feed
MatthewJ
Calcite | Level 5

How can I create a format that is functionally equivalent to PERCENTw.d, but with the string \% appearing instead of the % sign?

 

I understand that PERCENTw.d operates by multiplying a term by 100, converting to BESTw.d, and then appending a % symbol.  But I have not been able to reconstruct this process. 

 

I have tried this:

proc fcmp outlib=work.functions.smd;
 function LPCfunc(x) $;
 return(cats(100*x,'\%'));
 endsub;
run;

options cmplib=(work.functions);

proc format;
 value LPC  other=[LPCfunc()];
 run;

This function LPCfunc seems to work, and according to the log, a format called LPC is being generated.  But I cannot seem to call it.  When I try using it in a format declaration, the variable ends up having format BEST12.:

data temp1;
set temp1;
format C percent10.4;
run;

data temp1;
set temp1; 
format E LPC.;
D=LPCfunc(C); 
E=C;
run;

--------

 

I am using SAS for Windows 9.4 TS Level 1M0.

3 REPLIES 3
Reeza
Super User

Your code is partially correct.

How you create the format is correct, how you're trying to use it perhaps not?

 

This works for me:

 

 data test;
 set sashelp.class;
 weight2=weight/100;
 format weight2 lpc.;
 run;

 proc print data=test;
 run;

 Thsi is what I get:

 

 Obs    Name       Sex    Age    Height    Weight    weight2

                    1    Alfred      M      14     69.0      112.5    112.5\%
                    2    Alice       F      13     56.5       84.0    84\%
                    3    Barbara     F      13     65.3       98.0    98\%
                    4    Carol       F      14     62.8      102.5    102.5\%
                    5    Henry       M      14     63.5      102.5    102.5\%
                    6    James       M      12     57.3       83.0    83\%
                    7    Jane        F      12     59.8       84.5    84.5\%
                    8    Janet       F      15     62.5      112.5    112.5\%
                    9    Jeffrey     M      13     62.5       84.0    84\%
                   10    John        M      12     59.0       99.5    99.5\%
                   11    Joyce       F      11     51.3       50.5    50.5\%
                   12    Judy        F      14     64.3       90.0    90\%
                   13    Louise      F      12     56.3       77.0    77\%
                   14    Mary        F      15     66.5      112.0    112\%
                   15    Philip      M      16     72.0      150.0    150\%
                   16    Robert      M      12     64.8      128.0    128\%
                   17    Ronald      M      15     67.0      133.0    133\%
                   18    Thomas      M      11     57.5       85.0    85\%
                   19    William     M      15     66.5      112.0    112\%

 

PGStats
Opal | Level 21

You could use a picture format. Something like this:

 

proc format;
picture lpc
-1 -< 0 = '009.99\%)' (mult=10000 prefix='(')
0 - high = '009.99\%' (mult=10000);
run;

data _null_;
do x = -1, -0.999, -0.5, -0.05, 0, 0.01, 0.5, 1.5555, 2;
    put x= 7.2 +5 x lpc10.;
    end;
run; 
x=-1.00      (100.00\%)
x=-1.00       (99.90\%)
x=-0.50       (50.00\%)
x=-0.05        (5.00\%)
x=0.00          0.00\%
x=0.01          1.00\%
x=0.50         50.00\%
x=1.56        155.55\%
x=2.00        200.00\%
PG
ChrisHemedinger
Community Manager

Also, make sure that WORK is in your FMTSEARCH path, assuming you're placing the new format into the WORK library:

 

options insert(fmtsearch=(WORK));
Check out SAS Innovate on-demand content! Watch the main stage sessions, keynotes, and over 20 technical breakout sessions!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 801 views
  • 5 likes
  • 4 in conversation