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

Hello,

Below is the program. When I apply format to max it works perfectly as expected, but I was trying to use input statement and the results did not look right at all. One of my colleagues also suggested I can re-write it as max1= input(put((n1/n2),4.1),best.); but I still did not understand why input is converting numeric values to character in the first place. Any help?

 

data dryrun;
  input n1 n2;
  max = n1/n2;
  max1= input((n1/n2),4.1);


format max 4.1;
datalines;
37 53
40 52
39 52
;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

The input function requires a character value. So when you feed it a numeric value it converts it into a character value, usually using some form of BEST format. Then "inputs" the result.

 

The question is why would you even attempt an input of such a thing? What do you expect to result?

Generally the approach would be to do a numeric calculation and round the result if you don't want more than one decimal.

Perhaps

max = round( n1/n2, 0.1);

Or show us the explicit result you are expecting/wanting.

View solution in original post

2 REPLIES 2
ballardw
Super User

The input function requires a character value. So when you feed it a numeric value it converts it into a character value, usually using some form of BEST format. Then "inputs" the result.

 

The question is why would you even attempt an input of such a thing? What do you expect to result?

Generally the approach would be to do a numeric calculation and round the result if you don't want more than one decimal.

Perhaps

max = round( n1/n2, 0.1);

Or show us the explicit result you are expecting/wanting.

Tommer
Obsidian | Level 7
thanks @ballardw I was fixing a lengthy existing program where I came across using input function throughout the program in this way and noticed the conversion and that the values did not look right. I am assuming it was used to display it in 4.1 format using input function and numeric to numeric conversion. But I was not clear as why it did not work. Now, I get it. It was looking for a character value and thus, the automatic conversion occurred.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 775 views
  • 1 like
  • 2 in conversation