Help using Base SAS procedures

PUT Function

Accepted Solution Solved
Reply
Super Contributor
Posts: 1,040
Accepted Solution

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: 17,784

Re: PUT Function

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:

-Lleft aligns the value.
-Ccenters the value.
-Rright 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.

View solution in original post


All Replies
Solution
‎12-19-2013 12:30 PM
Super User
Posts: 17,784

Re: PUT Function

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:

-Lleft aligns the value.
-Ccenters the value.
-Rright 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,040

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

Respected Advisor
Posts: 3,777

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,040

Re: PUT Function

Bcos i want to categorize based on this variable

Respected Advisor
Posts: 3,777

Re: PUT Function

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

Super Contributor
Posts: 1,040

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: 17,784

Re: PUT Function

No.

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

Respected Advisor
Posts: 3,777

Re: PUT Function

You don't have to.  Do you know what -L does?

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 397 views
  • 6 likes
  • 3 in conversation