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
Opal | Level 21

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 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 728 views
  • 3 likes
  • 5 in conversation