Hi SAS frens,
I'd like to use PROC FORMAT to recode Weight into an Injection Volume category but I get a NOTE (considered an Error by my company and will not pass validation) on the Numeric to Character conversion. How do I avoid this? I'd like to not use IF/THEN logic because my list is quite long.
data have;
input id weight @;
datalines;
1008 31.2
1009 47.8
1010 57.5
1011 95.5
1012 106.1
1013 110.0
1014 125.8
1015 166.3
;
run;
proc format;
invalue vol3_
30.0 - 40.8 = 0.2
40.9 - 57.4 = 0.3
57.5 - 74.1 = 0.4
74.2 - 90.8 = 0.5
90.9 - 107.4 = 0.6
107.5 - 124.1 = 0.7
124.2 - 140.8 = 0.8
140.9 - 157.4 = 0.9
157.5 - 174.1 = 1.0
174.2 - 180.0 = 1.1;
run;
data want;
set have;
inj_vol=input(weight, vol3_.);
run;
Thank you 😁
INPUT function expect text values so control the conversion to text of your existing numeric value with the PUT function and an appropriate format.
The -L option with the Put function left justifies the value so there are not leading spaces which might confuse your informat.
data want; set have; inj_vol=input(put(weight,best8. -L), vol3_.); run;
OR create a Format and INPUT the formatted value.
inj_vol = input (put(weight,yourvolfmt. -L),8.);
You want to be very cautious about ranges of character values, which the Informat actually stores for the start and end values. Note that your informat will treat a value like 40.8999999 as if it is 40.8 because of the rules for comparing character values.
You may want to specify an OTHER option in the value ranges with the _error_ assignment to create notes in the log about unexpected values.
Example, note the added row of data in the Have with the value of 3000.
data have; input id weight @; datalines; 1008 31.2 1009 47.8 1010 57.5 1011 95.5 1012 106.1 1013 110.0 1014 125.8 1015 166.3 1016 3000 ; run; proc format library=work cntlout=work.cntlout; invalue vol3_ 30.0 - 40.8 = 0.2 40.9 - 57.4 = 0.3 57.5 - 74.1 = 0.4 74.2 - 90.8 = 0.5 90.9 - 107.4 = 0.6 107.5 - 124.1 = 0.7 124.2 - 140.8 = 0.8 140.9 - 157.4 = 0.9 157.5 - 174.1 = 1.0 174.2 - 180.0 = 1.1 other = _error_ ; run; data want; set have; inj_vol=input(put(weight,best8. -L), vol3_.); run;
INPUT function expect text values so control the conversion to text of your existing numeric value with the PUT function and an appropriate format.
The -L option with the Put function left justifies the value so there are not leading spaces which might confuse your informat.
data want; set have; inj_vol=input(put(weight,best8. -L), vol3_.); run;
OR create a Format and INPUT the formatted value.
inj_vol = input (put(weight,yourvolfmt. -L),8.);
You want to be very cautious about ranges of character values, which the Informat actually stores for the start and end values. Note that your informat will treat a value like 40.8999999 as if it is 40.8 because of the rules for comparing character values.
You may want to specify an OTHER option in the value ranges with the _error_ assignment to create notes in the log about unexpected values.
Example, note the added row of data in the Have with the value of 3000.
data have; input id weight @; datalines; 1008 31.2 1009 47.8 1010 57.5 1011 95.5 1012 106.1 1013 110.0 1014 125.8 1015 166.3 1016 3000 ; run; proc format library=work cntlout=work.cntlout; invalue vol3_ 30.0 - 40.8 = 0.2 40.9 - 57.4 = 0.3 57.5 - 74.1 = 0.4 74.2 - 90.8 = 0.5 90.9 - 107.4 = 0.6 107.5 - 124.1 = 0.7 124.2 - 140.8 = 0.8 140.9 - 157.4 = 0.9 157.5 - 174.1 = 1.0 174.2 - 180.0 = 1.1 other = _error_ ; run; data want; set have; inj_vol=input(put(weight,best8. -L), vol3_.); run;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: