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

I want to display a simple pre-fix for decimal numbers contained within a variable based on the value of those decimal numbers.

 

I have a series of numbers on [0,1). if the numbers are less than 0.001, then I want the number to display as '<.001'.  Otherwise, I want to display the original value with an equal sign in front of it ('=[original number]');

 

I provide a sample dataset as well as the code that I used to try to accomplish this task. 

 

The PRINT procedure output shows that I am partly there, but not quite.  Basically, to get what I am after, the output would need to   display '<0.001' instead of '<0.000' for the first 2 observations. The last 3 observations output the way I want them to.

 

Hope some one can help me.

 

Thanks.

 

proc format;
picture numbers
low-<.001 = '000009.999'(prefix='<' mult=1000)
.001-high = '000009.999'(prefix='=' mult=1000);
run;

data have;
   input numbers;
   datalines;
0.0000
0.0001
0.0010
0.0200
0.0500
;

proc print data=have;
format numbers numbers.;
run;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

PICTURE formats support the NOEDIT option:

 

http://documentation.sas.com/?docsetId=proc&docsetTarget=p0n990vq8gxca6n1vnsracr6jp2c.htm&docsetVers...

 

So you could code your format in this (untested) fashion:

 

proc format;
picture numbers
low-<.001 = '<.001' (noedit)
.001-high = '000009.999'(prefix='=' mult=1000);
run;

 

You may need to play with the spacing to get all values to line up properly.

View solution in original post

2 REPLIES 2
Astounding
PROC Star

PICTURE formats support the NOEDIT option:

 

http://documentation.sas.com/?docsetId=proc&docsetTarget=p0n990vq8gxca6n1vnsracr6jp2c.htm&docsetVers...

 

So you could code your format in this (untested) fashion:

 

proc format;
picture numbers
low-<.001 = '<.001' (noedit)
.001-high = '000009.999'(prefix='=' mult=1000);
run;

 

You may need to play with the spacing to get all values to line up properly.

Varrelle
Quartz | Level 8

Hi.

 

Thanks for your help -- your solution worked perfectly for me.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 2 replies
  • 1141 views
  • 0 likes
  • 2 in conversation