Help using Base SAS procedures

put ( )

Reply
Regular Contributor
Posts: 173

put ( )

Hello all,

I thougth the PUT( ) function converts a variable from numeric to character. Am I wrong?

Does the following code convert a variable from numeric to character?


if Loan_No2 ne ' ' and loan_no2 ne 'NULL' then do;
numer_eloc_loan_num=Loan_No2;
eloc_loan_num=put(numer_eloc_loan_num,z10.);
end;
else do;
numer_eloc_loan_num=0;
eloc_loan_num=put(numer_eloc_loan_num,z10.);
end;

Thanks for any input !
Regular Contributor
Posts: 173

Re: put ( )

I guess I am confused about the "z10" in the ( ). Z10 (numeric) is the format being converted from. Is that right?

Thanks.
Super Contributor
Posts: 359

Re: put ( )

As long as eloc_loan_num is a character variable the z10. will put the number in as character keeping leading zeros.
Super Contributor
Posts: 474

Re: put ( )

put function will return a character representation of a numeric OR character value (variable, constant or expression) using a specified format (which must match with the source type value).

Things to remind:
- put function always returns a character value.
- the format specified must be of the same type of the source value.

data _null_;
X=put('XXXXX',$2.); * char to char;
Y=put(23,Z5.); * num to char;
put _all_;
run;

Check the online documentation here:
http://support.sas.com/documentation/cdl/en/lrdict/62618/HTML/default/a000199354.htm

Cheers from Portugal.

Daniel Santos @ www.cgd.pt
Ask a Question
Discussion stats
  • 3 replies
  • 1378 views
  • 0 likes
  • 3 in conversation