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

Hi,

I need a user defined format and I never used PROC Format before and I am a bit lost here.

 

I need a format like this:

 

Input Value: 0.571

Output Value: +/+ 57,1%

 

Input Value: -1.3

Output Value: -/- 130%

 

This is what I got so far:

 

Data numbers;
input values;
cards;
0.1119
0.2119
0.57119
-0.5134
2
40
-5
;
run;

proc format;

picture advperc
low -< 0 = '99.99 %' (prefix='-/- ' mult=10000)
0 - high = '99.99 %' (prefix='+/+ ' mult=10000);
run;

proc print data = numbers;
format values advperc.;
run;

 

I m not quite there yet. The last 3 lines are not right.

 

Thank you in advance

Dirk 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

Data numbers;
input values;
cards;
0.1119
0.2119
0.57119
-0.5134
2
40
-5
;
run;
proc format;
picture advperc
low - -1 = '00000 %' (prefix='+/+ ' mult=10000)
-1< -< 0 = '00.00 %' (prefix='-/- ' mult=10000)
0 - < 1 = '00.00 %' (prefix='+/+ ' mult=10000)
1 - high = '00000 %' (prefix='+/+ ' mult=10000);

run;
proc print data = numbers;
format values advperc.;
run;

View solution in original post

9 REPLIES 9
Ksharp
Super User

Data numbers;
input values;
cards;
0.1119
0.2119
0.57119
-0.5134
2
40
-5
;
run;
proc format;
picture advperc
low - -1 = '00000 %' (prefix='+/+ ' mult=10000)
-1< -< 0 = '00.00 %' (prefix='-/- ' mult=10000)
0 - < 1 = '00.00 %' (prefix='+/+ ' mult=10000)
1 - high = '00000 %' (prefix='+/+ ' mult=10000);

run;
proc print data = numbers;
format values advperc.;
run;
dirks
Quartz | Level 8

Thank you!

 

I had to add another 0 and it is working now:

 

1 - high = '000000 %' (prefix='+/+ ' mult=10000);

 

 

 

Best regards

Dirk

Ksharp
Super User

Add more 0s.

 


Data numbers;
input values;
cards;
0.1119
0.2119
0.57119
-0.5134
2
40
-5
;
run;
proc format;
picture advperc
low - -1 = '0000000 %' (prefix='-/- ' mult=10000)
-1< -< 0 = '00.00 %' (prefix='-/- ' mult=10000)
0 - < 1  = '00.00 %' (prefix='+/+ ' mult=10000)
1 - high = '0000000 %' (prefix='+/+ ' mult=10000);
run;
proc print data = numbers;
format values advperc.;
run;
Ksharp
Super User

Actually this could be more simple.

 


Data numbers;
input values;
cards;
0.1119
0.2119
0.57119
-0.5134
2
40
-5
;
run;
proc format;
picture advperc
low -< 0 = '0000000000.00 %' (prefix='-/- ' mult=10000)
0 - < high  = '0000000000.00 %' (prefix='+/+ ' mult=10000) ;
run;
proc print data = numbers;
format values advperc.;
run;
dirks
Quartz | Level 8
I just noticed that the positive numbers arent correct.

2 should be 200, 40 is 40000 and so on.
Ksharp
Super User

I don't understand.

200=2*100    ,whereas    40000=40*1000

dirks
Quartz | Level 8

I ve got this working now.

 

Data numbers;
input values;
cards;
 0.1119
 0.2119
 0.57119
 -0.5134
 2
 40
 -5
 ;
run; 

proc format;

picture advperc 
		low  -< 0		    = 	'0000.99 %' (prefix='-/- ' mult=10000)
		0   - high			=	'0000.99 %' (prefix='+/+ ' mult=10000);
run;

proc print data = numbers;
format values advperc.;
run;

 

dirks
Quartz | Level 8

I had a typo, 

 

2 = 200, 40 = 4000

 

Your first output gave me

 

SAS Output

Obs values1234567
+/+ 11.19 %
+/+ 21.19 %
+/+ 57.11 %
-/- 51.34 %
+/+ 20000 %
+/+ 400000 %
-/- 50000 %
Ksharp
Super User

I think you should multiply 100 not 10000.

 


Data numbers;
input values;
cards;
0.1119
0.2119
0.57119
-0.5134
2
40
-5
;
run;
proc format;
picture advperc
low -< 0 = '0000000000.99 %' (prefix='-/- ' mult=100)
0 - < high  = '0000000000.99 %' (prefix='+/+ ' mult=100) ;
run;
proc print data = numbers;
format values advperc.;
run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 9 replies
  • 2481 views
  • 3 likes
  • 2 in conversation