BookmarkSubscribeRSS Feed
0 Likes

Syntax

CALL PUTC(c-source, format <, new-string <, return-code >> )

CALL PUTN(n-source, format <, new-string <, return-code >> )


Arguments

c-source

specifies a character constant, constant, variable, or expression to which you want to apply the format.  

 

n-source

specifies a numeric constant, constant, variable, or expression to which you want to apply the format.  

 

format
contains a string with the SAS format that you want applied to the value that is specified in the source. ...

 

new-string

specifies a character variable in which to place the formatted value.

 

return-code

specifies a numeric variable for which received a return-code of 0,1 or 2

  • 0 - No error
  • 1 - no-match
  • 2 - format not found
  • (or more)

Example:

proc format;
  value $A
    '00'     ="00"
    '01','04'="foo"
    '02'     ="bar"
    '03'     ="sna"
  ;
data result; 
  do x = '00', 'AA'; 
    call putc(x, "$A.", y, rc); 
    if rc ne 0 
      then call missing (y);
    output;
  end;
run;

 

result:

x  y  
00 00
AA 

 

3 Comments
ballardw
Super User

Intended purpose? As in  why is this needed?

 

It seems like the only thing different from PUTN and PUTC is your return code. Which might mean from the return code 1 that a whole lot of changes to the way formats are currently created would be needed.

 

I am sure I am not the only person that will create a format that only explicitly formats a small range of values such as age < 18 to create that as a group but leaves the other ages "undefined" or not explicitly listed. Which might be considered as no match but I know that going in.

 

If I were worried about explicit contents of the FORMAT then use cntlout option in Proc Format to create a data set and then you have something in a data set to check.

 

PhilC
Rhodochrosite | Level 12

That is fair.  OK.

Kurt_Bremser
Super User

When defining a value format, it's good practice to set a value for other, which can then be used to detect a mismatch. Given this, the current put, putc and putn functions already do what you want, just in a slightly different way.