Help using Base SAS procedures

Add string with Proc Format

Accepted Solution Solved
Reply
Contributor
Posts: 50
Accepted Solution

Add string with Proc Format

[ Edited ]

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 


Accepted Solutions
Solution
‎11-09-2017 08:50 AM
Super User
Posts: 10,788

Re: Add string with Proc Format


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


All Replies
Solution
‎11-09-2017 08:50 AM
Super User
Posts: 10,788

Re: Add string with Proc Format


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;
Contributor
Posts: 50

Re: Add string with Proc Format

[ Edited ]

Thank you!

 

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

 

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

 

 

 

Best regards

Dirk

Super User
Posts: 10,788

Re: Add string with Proc Format

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;
Super User
Posts: 10,788

Re: Add string with Proc Format

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;
Contributor
Posts: 50

Re: Add string with Proc Format

I just noticed that the positive numbers arent correct.

2 should be 200, 40 is 40000 and so on.
Super User
Posts: 10,788

Re: Add string with Proc Format

I don't understand.

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

Contributor
Posts: 50

Re: Add string with Proc Format

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;

 

Contributor
Posts: 50

Re: Add string with Proc Format

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 %
Super User
Posts: 10,788

Re: Add string with Proc Format

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;
☑ This topic is solved.

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

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