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

Hi,

 

I have a variable estimate with value = 14.793 and it is in numeric format 12.3 . I would like to convert it to character format and do the following:

 

estimate = put(estimate,$12.);

 

But the result that I get is 15.000, and the format is still 12.3. ?

 

 

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
4 REPLIES 4
SASKiwi
PROC Star
estimate = put(estimate,12.3);
ilikesas
Barite | Level 11

Wow, it works!!!

 

Its just that I was expecting the $ sign since I wanted to convert to character, but I guess that is some SAS peculiarity.

 

Thank a lot!

ChrisNZ
Tourmaline | Level 20

$ is for formatting character variables. You format a numeric here.

ballardw
Super User

PUT creates character variables any time you use x= put (...) or x=Putn(...) or x=putc(...).

The format involved in the PUT portion controls what the resulting character varaible may look like. The format should match the variable type you are PUTting.

 

SAS will occasionaly help you by doing implicit conversion if you specify a numeric format for something that is character but looks numeric or specify a numeric variable and a character format though the results may not match what you expect.

Here is a brief example:

data junk;
   x= 25.4;
   y = put(x,$7.);
run;

Note that there is no Error but a warning is placed in the log and that the value of Y may not be as expected and has leading blanks.

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 4 replies
  • 27400 views
  • 2 likes
  • 4 in conversation