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

Hello,

I found this very helpful post on how to add a prefix like '+' to values, but found, as the last reply to that post suggests, that it doesn't work for non-integers like 0.1. I guess this has something to do with the fact that "The prefix is placed in front of the value's first significant digit" (documentation).

 

So my question is how do I get values like 0.1 to display like +0.1 ?

 

proc format;
	picture test
	0<-high= '0.0' (prefix='+');
run;

data hello;
input x;
cards;
0.1
;
run;

data _null_;
	set hello;
	call symputx('whatever',put(x,test.)); 
run;

%put &whatever.;

I get +1, but am trying to get +0.1. The Fill option just gives me something like 0+1.

 

Would appreciate any tips.

 

Thanks very much!

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

You would need to define each order of magnitude as a separate range:

 

0-<10 = ' 9.0' (prefix='+')

10-<100 = ' 90.0' (prefix='+')

 

etc.

View solution in original post

4 REPLIES 4
Astounding
PROC Star

Make a couple of changes to your format definition ... including leaving room for the prefix:

 

proc format;

picture test 0<-high= ' 9.0' (prefix='+');

run;

 

You may still have difficulty with larger numbers, but this will take care of the case that you asked about.

sm4
Quartz | Level 8 sm4
Quartz | Level 8

Thank you! Worked perfectly. 

So....if I change to 0<-high= ' 10.0' (prefix='+');, then I can make it work for values like 15.1...but this adds an extra 0 for 0.1, giving me +00.1

 

Is there a way I can make it work for a whole range of values (0.1 --> +0.1, 15.5 --> +15.5, 100.3 --> +100.3, same for negatives)? I.e., keep the number as it would have been otherwise, but just add a prefix?

 

Thanks very much!

Astounding
PROC Star

You would need to define each order of magnitude as a separate range:

 

0-<10 = ' 9.0' (prefix='+')

10-<100 = ' 90.0' (prefix='+')

 

etc.

sm4
Quartz | Level 8 sm4
Quartz | Level 8
Thank you!!!

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
  • 4 replies
  • 484 views
  • 2 likes
  • 2 in conversation