vivi11130704
vivi11130704

Reputation: 451

SAS Put statement - Why it can be used to convert char to number?

The code is very simple:

data test (keep = state state_num);
set raw1314.accident2013_prf;
  state_num= put(state,z2.);
run;

variable "state" contains state names and the output of this program is:

  Obs     STATE      state _num
   1      Alabama       01  

But isn't "put" function is used to convert numerical values into character values? Why it maps "Alabama" to "01" here?

Thanks in advance.

Upvotes: 0

Views: 791

Answers (1)

Reeza
Reeza

Reputation: 21274

Your variable STATE must be numeric (1) and have a format applied to it or character (01) with a format applied. If it was the character value of Alabama this would not occur.

data _null_;
x=put('Alabama', z2.);
put x;
run;

Results:

 55         
 56         data _null_;
 57         x=put('Alabama', z2.);
                         ___
                         484
 NOTE 484-185: Format $Z was not found or could not be loaded.

 58         put x;
 59         run;
 Al

Upvotes: 2

Related Questions