BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
theponcer
Quartz | Level 8

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.

 

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

@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).

View solution in original post

4 REPLIES 4
novinosrin
Tourmaline | Level 20

Try this change

 

retain fmtname 'test_format' type 'N';

followed by

 

Util=put(tier,test_format.);

 

FreelanceReinh
Jade | Level 19

@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).

ballardw
Super User

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.

theponcer
Quartz | Level 8

Thanks - this clears up my confusion!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 2375 views
  • 2 likes
  • 4 in conversation