DATA Step, Macro, Functions and more

format max dec when creating new variable

Accepted Solution Solved
Reply
Regular Contributor
Posts: 180
Accepted Solution

format max dec when creating new variable

Hi all!

 

If I write this to calculate a percentage in a data step,  where do I write the maxdec=2  so that percent_miss is only 2 decimals?

 

data gaq_4 (drop=_TYPE_ _FREQ_);
set gaq_1 (rename=(_FREQ_=Study_Population));
Percent_Miss=nmiss/Study_Population;

run;

 

Thank you!!


Accepted Solutions
Solution
‎11-10-2017 02:27 PM
Super User
Super User
Posts: 7,860

Re: format max dec when creating new variable

Are you asking how to round your results to 2 decimal places?

Use the ROUND() function.

Percent_Miss=round(nmiss/Study_Population, 0.01);

View solution in original post


All Replies
Super User
Posts: 22,875

Re: format max dec when creating new variable

MAXDEC is only an option in PROC MEANS. 

 

You use a FORMAT or ROUND in a data step or SQL to limit the decimal places.

Solution
‎11-10-2017 02:27 PM
Super User
Super User
Posts: 7,860

Re: format max dec when creating new variable

Are you asking how to round your results to 2 decimal places?

Use the ROUND() function.

Percent_Miss=round(nmiss/Study_Population, 0.01);
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 210 views
  • 0 likes
  • 3 in conversation