- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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).
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Try this change
retain fmtname 'test_format' type 'N';
followed by
Util=put(tier,test_format.);
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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).
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks - this clears up my confusion!