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.

 

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!

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