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

Hello,

 

I am struggling to format numeric data that is always length of 7 and contains no decimals or commas, WITH decimals.

 

i.e.

 

0030316 --> 303.16

1836960 --> 18369.60

 

Obviously, this is easy and I am an idiot.

 

Thank you for your help!!!

1 ACCEPTED SOLUTION

Accepted Solutions
GBL__
Quartz | Level 8

I used

 

INPUT
		customer_name					$
		account_number					$
		loan_number					$
		loan_date					:	anydtdte6.
		maturity_date					:	anydtdte6.
		term
		payment_amount					:	best7.2
		odd_payment_amount				:	best7.2
		total_of_payments				:	best7.2 ;

 And then formatted it as Dollarw.d

View solution in original post

10 REPLIES 10
PaigeMiller
Diamond | Level 26

Numeric data never has leading zeros, so it is either character, or formatted somehow.

 

Please show us the PROC CONTENTS output for this variable.

--
Paige Miller
GBL__
Quartz | Level 8

Apologies for not being clear, I am reading this data in from an external text file like this:

 

"CUSTOMER NAME","ACCOUNT NUMBER","LOAN NUMBER","LOAN DATE","MATURITY DATE","TERM","PAYMENT AMOUNT","ODD PAYMENT AMOUNT","TOTAL OF PAYMENTS" 
"******, ****","15028","28","010919","011724","060","0030616","0030616","1836960"
PaigeMiller
Diamond | Level 26

But I specifically asked for the PROC CONTENTS output of your SAS data set, showing the results for this variable of interest.

 

Your presenting the external text file does not move us forward to understanding how to obtain the desired result.

--
Paige Miller
GBL__
Quartz | Level 8
Variables in Creation Order
# Variable Type Len
1 customer_name Char 25
2 account_number Char 8
3 loan_number Char 5
4 loan_date Num 8
5 maturity_date Num 8
6 term Num 8
7 payment_amount Num 7
8 odd_payment_amount Num 7
9 total_of_payments Num 7

 

I told you it was a number with a length of 7, so here is also a picture that says it is a number with a length of 7

PaigeMiller
Diamond | Level 26

Edit: Ignore this

Please try PROC CONTENTS with the DETAILS option

 

PROC CONTENTS DATA=yourdatasetname DETAILS;

RUN:

--
Paige Miller
PaigeMiller
Diamond | Level 26

So it is numeric with length 7, so it can't have leading zeros.

 

To get the output the way you want it, use 

 

format payment_amount dollar16.2;
--
Paige Miller
GBL__
Quartz | Level 8

When I format as dollar16.2 I get $30,616.00

PaigeMiller
Diamond | Level 26

@GBL__ wrote:

When I format as dollar16.2 I get $30,616.00


You need to divide by 100 first.

--
Paige Miller
GBL__
Quartz | Level 8

I used

 

INPUT
		customer_name					$
		account_number					$
		loan_number					$
		loan_date					:	anydtdte6.
		maturity_date					:	anydtdte6.
		term
		payment_amount					:	best7.2
		odd_payment_amount				:	best7.2
		total_of_payments				:	best7.2 ;

 And then formatted it as Dollarw.d

Tom
Super User Tom
Super User

The way to have SAS put in an implied decimal point when converting text to numbers is to specify the number of decimal places in the INFORMAT.  So if the field is always 7 characters wide and you want to interpret the last 2 as being after the decimal point then use the 7.2 informat.  

 

I think you confused people by using the word FORMAT in your question. FORMATs are something you attach to a value that you already have in a SAS variable.  INFORMATs are what determine how to interpret text and convert it to values.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 10 replies
  • 930 views
  • 0 likes
  • 3 in conversation