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

 

I want to use proc format on the values below. Example:  1.0-1.9 is 'Pre-functional'. I have to format them as character due to other values such as P1,P2, etc.

 

will this work?

 

proc format;

value $ engproffmt

'1.0 - < 1.9' = 'Pre-functional';

 

 

1.0-1.9

2.0-2.9

3.0-3.9

4.0-4.9

5.0-5.9

6.0

P1

P2

P3

P4

8

9

W

X

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

You may want to run this code and see if the formatted values match what you would expect with your data.

Normally in a numeric format the -<  means "up to but not including" so 1.9999 would be "pre-functional" and 2 would be "something else". Note that characters use the active sort sequence (ASCII or EBCDIC depending on environment) and does a character-by-character left-to-right comparison for range membership. Some things may not quite what you expect such as values of 1 and 2 (note no decimal present)

proc format library=work;
value $ engproffmt
'1.0' -< '2.0' = 'Pre-functional'
'2.0' -< '2.9' = 'Something else'
'3.0' -< '3.9' = 'YadaYada'
;
run;
data example;
   input x $;
/* so you can see the unformatted value
in proc print below*/
y=x; datalines; 1.0 1.01 1.1 1 1.A 10 1.9 1.90 1.93 2 2. 2.0 ; run; proc print data=example; format x $engproffmt.; run;

Explicit values may be better if known.

 

View solution in original post

4 REPLIES 4
Astounding
PROC Star

Programming ranges within a character format is tricky and prone to error.  As a general rule, avoid it whenever possible.  For this limited case, you could use:

 

value $engproffmt

'1.0' - '1.9' = 'Pre-functional'

'2.0' - '2.9' = 'Next level description';

 

VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

I do not believe what you have will work with the sample data you have provided.

You may have to list each stringed value.

here is a nice link to formatting.

 

http://www2.sas.com/proceedings/sugi27/p056-27.pdf

 

 

ballardw
Super User

You may want to run this code and see if the formatted values match what you would expect with your data.

Normally in a numeric format the -<  means "up to but not including" so 1.9999 would be "pre-functional" and 2 would be "something else". Note that characters use the active sort sequence (ASCII or EBCDIC depending on environment) and does a character-by-character left-to-right comparison for range membership. Some things may not quite what you expect such as values of 1 and 2 (note no decimal present)

proc format library=work;
value $ engproffmt
'1.0' -< '2.0' = 'Pre-functional'
'2.0' -< '2.9' = 'Something else'
'3.0' -< '3.9' = 'YadaYada'
;
run;
data example;
   input x $;
/* so you can see the unformatted value
in proc print below*/
y=x; datalines; 1.0 1.01 1.1 1 1.A 10 1.9 1.90 1.93 2 2. 2.0 ; run; proc print data=example; format x $engproffmt.; run;

Explicit values may be better if known.

 

Reeza
Super User
Is your input data mixed format? If so, I suspect some IF THEN statements are likely more efficient and less error prone. Create a generic else to catch issues though. Use ANYALPHA or NOTDIGIT to test if a value is all numeric.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

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
  • 1140 views
  • 3 likes
  • 5 in conversation