## PUT Function

Solved
Super Contributor
Posts: 1,041

# PUT Function

Hi,

could someone explain to me why we have to write the format and -l while we are converting Numeric to charecter(using PUT)  in the below example??

HAVE

ID   SCORES(numeric)

10       .

11       0

12       3

13       1

14       0

15        .

16        .

data want;

set have;

length _scores   \$ 20;

_scores=put(scores,20. -l );

run;

Thanks

Accepted Solutions
Solution
‎12-19-2013 12:30 PM
Super User
Posts: 23,683

RTM

## Syntax

PUT(source, format.)

### Required Arguments

source
identifies the constant, variable, or expression whose value you want to reformat. The sourceargument can be character or numeric.

format.

contains the SAS format that you want applied to the value that is specified in the source. This argument must be the name of a format with a period and optional width and decimal specifications, not a character constant, variable, or expression. By default, if the source is numeric, the resulting string is right aligned, and if the source is character, the result is left aligned. To override the default alignment, you can add an alignment specification to a format:

 -L left aligns the value. -C centers the value. -R right aligns the value.

Restriction:The format. must be of the same type as the source, either character or numeric. That is, if the source is character, the format name must begin with a dollar sign, but if the source is numeric, the format name must not begin with a dollar sign.

All Replies
Solution
‎12-19-2013 12:30 PM
Super User
Posts: 23,683

RTM

## Syntax

PUT(source, format.)

### Required Arguments

source
identifies the constant, variable, or expression whose value you want to reformat. The sourceargument can be character or numeric.

format.

contains the SAS format that you want applied to the value that is specified in the source. This argument must be the name of a format with a period and optional width and decimal specifications, not a character constant, variable, or expression. By default, if the source is numeric, the resulting string is right aligned, and if the source is character, the result is left aligned. To override the default alignment, you can add an alignment specification to a format:

 -L left aligns the value. -C centers the value. -R right aligns the value.

Restriction:The format. must be of the same type as the source, either character or numeric. That is, if the source is character, the format name must begin with a dollar sign, but if the source is numeric, the format name must not begin with a dollar sign.

Super Contributor
Posts: 1,041

## Re: PUT Function

Hi ,

Thanks for the responses...

I was also wondering : the _scores variable is charecter in the WANT dataset and still has the dots instead of SPACES!!!!

ALSO does it matter during analysis for either alligning it Left or center or right?????

Regards

Posts: 3,852

## Re: PUT Function

Why are you converting this perfectly good numeric variable to character anyway.  I can see no avantage to that.

Super Contributor
Posts: 1,041

## Re: PUT Function

Bcos i want to categorize based on this variable

Posts: 3,852

## Re: PUT Function

You don't need to convert to character to use is as categorical variable.

Super Contributor
Posts: 1,041

## Re: PUT Function

Interesting. I will also check my code again to verify if the numeric variable can also be grouped in the REPORT

May be in this case it is converted to charecter only because of the report  presentation .to show it to the left instead of the right side.

Do u agree??

Thanks

Super User
Posts: 23,683

## Re: PUT Function

No.

Doesn't Proc report allow you to justify the data, left/right/center?

Posts: 3,852