DATA Step, Macro, Functions and more

Percentage

Accepted Solution Solved
Reply
Contributor
Posts: 33
Accepted Solution

Percentage

Hello,
I have a database (.txt) made up of percentage:

50 

40

20

10

41

But they must not be in this form

Which format or informat would allow to have this in sas table :

0.5%

0,4%

0,2%

0.1%

0,41%

 

Thanks for your help


Accepted Solutions
Solution
‎01-14-2018 04:46 AM
PROC Star
Posts: 8,112

Re: Percentage

Depending upon what you actually want, here is an example of the percent format and informat on your example data:

data have;
  informat percent1 percent3.2;
  informat percent2 percent3.3;
  informat percent3 percent3.4;
  format percent1-percent3 percent6.2;
  input @1 percent1 @1 percent2 @1 percent3;
  x1=10*percent1;
  x2=10*percent2;
  x3=10*percent3;
  cards;
50 
40
20
10
41
;

Art, CEO, AnalystFinder.com

 

View solution in original post


All Replies
Valued Guide
Posts: 530

Re: Percentage

If you print these numbers using the PERCENT. format that is what you will get. Please be aware that it is not how you store the numbers in the table that determine how they are printed. That is what is controlled by the format definition. So SAS separates the data and the presention. As this is an important concept I advise you to read up on formats and informats.

 

Hope this helps,

-- Jan.

Solution
‎01-14-2018 04:46 AM
PROC Star
Posts: 8,112

Re: Percentage

Depending upon what you actually want, here is an example of the percent format and informat on your example data:

data have;
  informat percent1 percent3.2;
  informat percent2 percent3.3;
  informat percent3 percent3.4;
  format percent1-percent3 percent6.2;
  input @1 percent1 @1 percent2 @1 percent3;
  x1=10*percent1;
  x2=10*percent2;
  x3=10*percent3;
  cards;
50 
40
20
10
41
;

Art, CEO, AnalystFinder.com

 

Super User
Posts: 6,540

Re: Percentage

Are you sure this is what you want?  The math is off here.  Even if the number 50 refers to 50 percent, you can represent that as either 50% or 0.5.  But 0.5% means something different.

☑ This topic is solved.

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

Discussion stats
  • 3 replies
  • 209 views
  • 0 likes
  • 4 in conversation