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

please help solve the ollowing problems 

 we have "x" variable vith 1233211321 value.

1.Make SAS to read this value in this way 1233213.21

2.After that multiple that value by 3

3.Introduce thyat value like this $3,699,639,6

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Do ALL of your values you need to read end in exactly 2 implied decimal? (Implied decimal is the term for when the decimal portion of a value is not shown but you know it is there.)

If so then you use a format long enough to read all the characters and use the fixed decimal to indicate the value.

 

data example;
   input x 16.2;
   y= x*3;
   format x 16.2 y dollar17.1;
datalines;
1233211321 
123456
1289 
123456789122
;

The 16.2 on the input statement tells SAS to read upto 16 characters as numeric and treat the last two digits a decimal if there is not a decimal in the value. The FORMAT displays the value of a SAS variable according to your desire. I am not sure that you actually intended to display the currency value with one decimal as you show commas all through the value and the shown s $3,699,639,6 is incorrect for all the currency display systems I am familiar with.

 

If only SOME of your values have the implied decimal and are integers then you need to provide a rule for telling which is which as that is a non-trivial exercise.

 


@Hayk290489 wrote:

please help solve the ollowing problems 

 we have "x" variable vith 1233211321 value.

1.Make SAS to read this value in this way 1233213.21

2.After that multiple that value by 3

3.Introduce thyat value like this $3,699,639,6


 

View solution in original post

1 REPLY 1
ballardw
Super User

Do ALL of your values you need to read end in exactly 2 implied decimal? (Implied decimal is the term for when the decimal portion of a value is not shown but you know it is there.)

If so then you use a format long enough to read all the characters and use the fixed decimal to indicate the value.

 

data example;
   input x 16.2;
   y= x*3;
   format x 16.2 y dollar17.1;
datalines;
1233211321 
123456
1289 
123456789122
;

The 16.2 on the input statement tells SAS to read upto 16 characters as numeric and treat the last two digits a decimal if there is not a decimal in the value. The FORMAT displays the value of a SAS variable according to your desire. I am not sure that you actually intended to display the currency value with one decimal as you show commas all through the value and the shown s $3,699,639,6 is incorrect for all the currency display systems I am familiar with.

 

If only SOME of your values have the implied decimal and are integers then you need to provide a rule for telling which is which as that is a non-trivial exercise.

 


@Hayk290489 wrote:

please help solve the ollowing problems 

 we have "x" variable vith 1233211321 value.

1.Make SAS to read this value in this way 1233213.21

2.After that multiple that value by 3

3.Introduce thyat value like this $3,699,639,6