BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
robertrao
Quartz | Level 8

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

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

8 REPLIES 8
Reeza
Super User

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.

robertrao
Quartz | Level 8

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

data_null__
Jade | Level 19

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

robertrao
Quartz | Level 8

Bcos i want to categorize based on this variable

data_null__
Jade | Level 19

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

robertrao
Quartz | Level 8

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

Reeza
Super User

No.

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

data_null__
Jade | Level 19

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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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