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

 

Here is the code

data Roc_1_01a;
set Roc_1_01; 

ROC_01=scan(_id,1," "); 

ROC_01a=ROC_01*1; 
format ROC_01a 8.2; 

ROC_00=input(ROC_01,8.2);

run;

 

 

So when I just times the character variable by 1, it is correct. I was taught not to do it that way for some reason that I can't remember.   I was told to use the input statement, which I have done. However, the input statement didn't yield the correct results.

 

this is my dataset. If you look at the 3rd row, you see the character variable -15. When I use the input statement, it converts it to -0.15 instead of -15. How do I write the code using the input statement to make it appear correct?

 

screen.png

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@Tpham wrote:

 

Here is the code

data Roc_1_01a;
set Roc_1_01; 

ROC_01=scan(_id,1," "); 

ROC_01a=ROC_01*1; 
format ROC_01a 8.2; 

ROC_00=input(ROC_01,8.2);

run;

 

 

So when I just times the character variable by 1, it is correct. I was taught not to do it that way for some reason that I can't remember.   I was told to use the input statement, which I have done. However, the input statement didn't yield the correct results.

 

this is my dataset. If you look at the 3rd row, you see the character variable -15. When I use the input statement, it converts it to -0.15 instead of -15. How do I write the code using the input statement to make it appear correct?

 

screen.png

 

 


When you use a format with a stated number of decimals you are telling sas that all of the variables without a decimal in input will be read with implied decimals.

I suggest for your use to the BEST. informat if your input has mixed numbers of decimal places.

See

data example;
   string= '1234';
   val1= input(string,best.);
   val2 = input(string,8.0);
   val3 = input(string,8.1);
   val4 = input(string,8.2);
   val5 = input(string,8.3);
   val6 = input(string,8.4);
   
run;

The input function with formats has had this behavior since the days of punch cards. It was very common to define fields on punch cards with "implied decimals" to save character space. So if columns 10 through 20 contained currency values columns 19 and 20 would have the decimal portion but the values would look like 12345678987 and the program was expected to place the decimal before the 87 using an 11.2 informat.

 

View solution in original post

1 REPLY 1
ballardw
Super User

@Tpham wrote:

 

Here is the code

data Roc_1_01a;
set Roc_1_01; 

ROC_01=scan(_id,1," "); 

ROC_01a=ROC_01*1; 
format ROC_01a 8.2; 

ROC_00=input(ROC_01,8.2);

run;

 

 

So when I just times the character variable by 1, it is correct. I was taught not to do it that way for some reason that I can't remember.   I was told to use the input statement, which I have done. However, the input statement didn't yield the correct results.

 

this is my dataset. If you look at the 3rd row, you see the character variable -15. When I use the input statement, it converts it to -0.15 instead of -15. How do I write the code using the input statement to make it appear correct?

 

screen.png

 

 


When you use a format with a stated number of decimals you are telling sas that all of the variables without a decimal in input will be read with implied decimals.

I suggest for your use to the BEST. informat if your input has mixed numbers of decimal places.

See

data example;
   string= '1234';
   val1= input(string,best.);
   val2 = input(string,8.0);
   val3 = input(string,8.1);
   val4 = input(string,8.2);
   val5 = input(string,8.3);
   val6 = input(string,8.4);
   
run;

The input function with formats has had this behavior since the days of punch cards. It was very common to define fields on punch cards with "implied decimals" to save character space. So if columns 10 through 20 contained currency values columns 19 and 20 would have the decimal portion but the values would look like 12345678987 and the program was expected to place the decimal before the 87 using an 11.2 informat.

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1 reply
  • 875 views
  • 0 likes
  • 2 in conversation