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

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

1 ACCEPTED SOLUTION

Accepted Solutions
yabwon
Onyx | Level 15

Hi,

 

start with reading the doc:

https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/leforinforref/n11m54nggvjybhn1w2a8mbczw04q.ht...

for dateW. format: "Writes date values in the form ddmmmyy, ddmmmyyyy, or dd-mmm-yyyy."

https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/leforinforref/n16vcb736tge20n1ex3yxx49fzqa.ht...

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."

https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/leforinforref/p03sgbuduqemljn1nqj7qm1leql9.ht...

 

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

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



View solution in original post

3 REPLIES 3
yabwon
Onyx | Level 15

Hi,

 

start with reading the doc:

https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/leforinforref/n11m54nggvjybhn1w2a8mbczw04q.ht...

for dateW. format: "Writes date values in the form ddmmmyy, ddmmmyyyy, or dd-mmm-yyyy."

https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/leforinforref/n16vcb736tge20n1ex3yxx49fzqa.ht...

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."

https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/leforinforref/p03sgbuduqemljn1nqj7qm1leql9.ht...

 

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

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



Tom
Super User Tom
Super User

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.

ballardw
Super User

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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 3 replies
  • 806 views
  • 5 likes
  • 4 in conversation