I am trying to create and use a user-defined format to convert a numeric value to a character value.
Here is my test code:
data format_in;
input begin $ 1-3 end $ 5-8 amount $ 10-12;
datalines;
1 1 RG
2 2 RG
3 3 RB
4 4 RB
5 5 RS
;
data ctrl;
length label $ 11;
set format_in(rename=(begin=start amount=label)) end=last;
retain fmtname 'test_format' type 'C';
output;
if last then do;
hlo='O';
label='***ERROR***';
output;
end;
run;
proc format library=work cntlin=ctrl;
run;
proc sql; create table test
(Tier num(1));
insert into test
values(1)
values(2)
values(3)
values(4)
values(5);
run;
data test2;
set test;
Util=put(tier,$test_format.);
run;
However, this returns the following errors:
70 data test2; 71 set test; 72 Util=put(tier,$test_format.); _____________ 484 WARNING: Variable Tier has already been defined as numeric. NOTE 484-185: Format TEST_FORMAT was not found or could not be loaded.
Does anyone know what is going on? I am not sure why the format can't be loaded or found when I just created it.
@theponcer wrote:70 data test2; 71 set test; 72 Util=put(tier,$test_format.); _____________ 484 WARNING: Variable Tier has already been defined as numeric. NOTE 484-185: Format TEST_FORMAT was not found or could not be loaded.Does anyone know what is going on? I am not sure why the format can't be loaded or found when I just created it.
A character format cannot be applied to a numeric variable, hence the warning. Having noticed that tier is a numeric variable, SAS searches for a numeric format with the specified name, but ignoring the dollar sign. The search is unsuccessful in this case, hence the note (which does not state that format $TEST_FORMAT was not found).
Try this change
retain fmtname 'test_format' type 'N';
followed by
Util=put(tier,test_format.);
@theponcer wrote:70 data test2; 71 set test; 72 Util=put(tier,$test_format.); _____________ 484 WARNING: Variable Tier has already been defined as numeric. NOTE 484-185: Format TEST_FORMAT was not found or could not be loaded.Does anyone know what is going on? I am not sure why the format can't be loaded or found when I just created it.
A character format cannot be applied to a numeric variable, hence the warning. Having noticed that tier is a numeric variable, SAS searches for a numeric format with the specified name, but ignoring the dollar sign. The search is unsuccessful in this case, hence the note (which does not state that format $TEST_FORMAT was not found).
Use
data ctrl; length label $ 11; set format_in(rename=(begin=start amount=label)) end=last; retain fmtname 'test_format' type 'N'; output; if last then do; hlo='O'; label='***ERROR***'; output; end; run;
The PUT function is what creates the character value, not the type of the format.
Thanks - this clears up my confusion!
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 16. Read more here about why you should contribute and what is in it for you!
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: