Hello Team, I have serious problems understanding the date and dollar formats. In fact, in certain exercises, dollar7 or a dollar12 are sometimes used. Can you better explain to me when should I use dollar7, dollar8 dollar9, dollar10, dollar11, or dollar12
here is an example I got I used dollar12. but in the correction one uses dollar7. and I can't understand the reasons they gave. It's the same problem with the date format using date7, date8 date 9, and so on.
data results.output13; set cert.input13; Chdate=put(date1,date9.); num1=input(Charnum,dollar7.); run;
Thank's for your comprehension
Hi,
start with reading the doc:
for dateW. format: "Writes date values in the form ddmmmyy, ddmmmyyyy, or dd-mmm-yyyy."
for dollarW.D format: "Writes numeric values with a leading dollar sign, a comma that separates every three digits, and a period that separates the decimal fraction."
W - indicates width of a text printed by format, D - indicates number of digits to the right of the decimal point
All the best
Bart
Hi,
start with reading the doc:
for dateW. format: "Writes date values in the form ddmmmyy, ddmmmyyyy, or dd-mmm-yyyy."
for dollarW.D format: "Writes numeric values with a leading dollar sign, a comma that separates every three digits, and a period that separates the decimal fraction."
W - indicates width of a text printed by format, D - indicates number of digits to the right of the decimal point
All the best
Bart
The first thing you need to learn is the difference between a FORMAT and an INFORMAT. Your code is using one of each.
Formats convert values into text. Informats convert text into values.
The DOLLAR format writes numeric values with a $ prefix and thousand separators. There isn't any DOLLAR informat. But SAS will recognize DOLLAR as an alias for the COMMA informat. That informat will ignore $ and commas in the source string when converting the string into a number.
The w.d part of a format or informat specification indicates the number to total characters and the number of characters after the decimal point.
Note than when using the INPUT() function, as in your second example, it does not mind if you use a width on the informat specification that is larger than the length of the text string you are asking it to convert. So unless there are trailing characters in that text string you want INPUT() to ignore you are probably best off just using a large number for the width. Note that each informat (or format) will have a maximum width that it supports that you can find in the documentation for the informat (or format). For the COMMA informat you are using the maximum width is 32.
Minor addition: Unless you really know what "implied decimal" means and is used for do not use the decimal portion of an informat. If you specify a decimal portion on an informat and the text value does not actually contain a decimal value then the informat would imply a value.
data example; input amount :comma12.2; datalines; $456.38 /*ignores currency symbol*/ 456.38 $45,638 /*ignores currency symbol and implies decimal*/ ;
If in the above case you want a value of 45638 for the third value use the Comma12. informat to avoid implying a decimal that is not there.
This behavior for informats is partially related to ancient days of data entry and keypunch card data where there was limited space on the cards. By implying a position for the decimal they did not actually use that print position on the card allowing more data per card.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.