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 |
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.
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';
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
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.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.