BookmarkSubscribeRSS Feed
potiu
Fluorite | Level 6

Hi,

 

I came across the following Put statements to convert from numerical to character:

 

char_var = put(num_var,6.);

apple1 = put(apple, 6);

Run;

 

apple1 = put(apple, best6.);

Run;

Both statements will produce the same result.
My question are (1) why there are different syntax which can produce the same output, (2) what is the 'best' means, and (3) how do we know what is the value to put in the w.d format?

 

Thank you. 

3 REPLIES 3
Kurt_Bremser
Super User

The statements will NOT produce the same result.

Run this and look at the result:

data test;
input numvar;
charvar1 = put(numvar,6.);
charvar2 = put(numvar,best6.);
cards;
1
6000
6.5431
1534.21
1109998
;
run;

Note obs 3 and 4

 

Kurt_Bremser
Super User

As for your question 3:

Maxim 3: Know your data.

Inspect your dataset, run some statistics to see maximum and minimum values, see if x-int(x) gives you fractions, and so on.

Reeza
Super User

@potiu wrote:

(1) why there are different syntax which can produce the same output,

 


There is A LOT of 'different' syntax that can produce the same output. 

FYI - this is a PUT() function, there is a PUT statement and they do differ.

 

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 3 replies
  • 920 views
  • 1 like
  • 3 in conversation