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

When I'm using format as 5.1 or 6.1 on z variable , I'm getting 100 percentage in z variable. I need it 99.9 as required output .please someone suggest on it...


data _null_;
x = 2202;
y= 2203;
z=x/y*100;
z1 = put(z,5.1);
put x y z z1= ;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

Hi:

  A picture format will not round the number. Here's some code to test, a slightly different version of your code.

proc format;
  picture pctnr low-high='099.9';
run;


data nums;
length z2 $5;
x = 2202;
y= 2203;
z=x/y*100;
z1=z;
z2 = put(z,pctnr.);
put x= y= z= z1= z2=;
run;

proc print data=nums label;
var x y z z1 z2;
label z='z uses sas format'
      z1='z1 uses picture custom format'
      z2='z2 is char var using picture format';
format z 5.1 z1 pctnr.;
run;

Cynthia

View solution in original post

2 REPLIES 2
Cynthia_sas
SAS Super FREQ

Hi:

  A picture format will not round the number. Here's some code to test, a slightly different version of your code.

proc format;
  picture pctnr low-high='099.9';
run;


data nums;
length z2 $5;
x = 2202;
y= 2203;
z=x/y*100;
z1=z;
z2 = put(z,pctnr.);
put x= y= z= z1= z2=;
run;

proc print data=nums label;
var x y z z1 z2;
label z='z uses sas format'
      z1='z1 uses picture custom format'
      z2='z2 is char var using picture format';
format z 5.1 z1 pctnr.;
run;

Cynthia

Kurt_Bremser
Super User

Be advised that 99.9 will be mathematically wrong, as 99.954607354 must be rounded up (per definition) if only 1 fractional digit can be displayed.

The more correct method would be to use a 5.2 format in the put() function.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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