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

hi,

 

i want to eliminate w.d note from these calculations

data test1;
calc=77;
call symputx('calc',calc);
run;

data test;
input numb;
datalines;
77
58
;

data test2;
set test;
total=numb/&calc*100;
total2=PUT (total,4.1);
run;

 

i've tried to round total

data test2;
set test;
total=round(numb/&calc*100,4.1);
total2=PUT (total,4.1);
run;

 

and it doesnt print me w.d but... i have wrong results, sas shows me that (77/77*100,4.1)=98.4 instead of 100. I don't understand this.

 

thank you for your help

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hi @Jedrzej,

 

Just to add the explanations:

  • The width w of the w.d format is the total width of the output field, including the decimal point and the minus sign, if any. So, format 4.1 is sufficient for 99.9, but for 100.0 you need 5.1 (and for -100.0 even 6.1).
  • The second argument of the ROUND function is the rounding unit. In your case 0.1 would be a typical value (although not helpful for the w.d format issue), whereas the very unusual 4.1 rounds 100 (=24.39024...*4.1) down to 98.4 (=24*4.1).

 

 

View solution in original post

6 REPLIES 6
sbxkoenk
SAS Super FREQ

Here you are.

By the way, do not use a macro variable to merge a single number to all records in another dataset.

Use the "if _N_=1 then set" technique instead.

data test1; calc=77; run;

data test;
 input numb;
 datalines;
77
58
;
run;

data test2;
 if _N_=1 then set test1;
 set test;
 total=numb/calc;
 put total= percent15.5;
 put total= percent10.0;
run;

Cheers,

Koen

Jedrzej
Obsidian | Level 7
hmm that doesn;t solve this problem
Shmuel
Garnet | Level 18

Define total2 as char type with appropriate length:

For format 4.2 assign LENGTH TOTAL2 $7; 

Jedrzej
Obsidian | Level 7
you mean this ?
data test2;
length total2 $7;
set test;
total=numb/&calc*100;
total2=PUT (total,4.2);
run;

doesn't work, still w.d is too small in log...
FreelanceReinh
Jade | Level 19

Hi @Jedrzej,

 

Just to add the explanations:

  • The width w of the w.d format is the total width of the output field, including the decimal point and the minus sign, if any. So, format 4.1 is sufficient for 99.9, but for 100.0 you need 5.1 (and for -100.0 even 6.1).
  • The second argument of the ROUND function is the rounding unit. In your case 0.1 would be a typical value (although not helpful for the w.d format issue), whereas the very unusual 4.1 rounds 100 (=24.39024...*4.1) down to 98.4 (=24*4.1).

 

 

PaigeMiller
Diamond | Level 26
total=round(numb/&calc*100,4.1);

rounds to the nearest multiple of 4.1. The nearest multiple of 4.1 to 100 (100 is the value of numb/&calc*100) is 24*4.1=98.4

 

If you want to round to the nearest decimal place i.e. nearest tenth, you would want round(numb/&calc*100,0.1)

--
Paige Miller

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!

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
  • 6 replies
  • 2860 views
  • 2 likes
  • 5 in conversation