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!
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.
Ready to level-up your skills? Choose your own adventure.