

{"id":11388,"date":"2018-03-22T07:31:26","date_gmt":"2018-03-22T07:31:26","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=11388"},"modified":"2021-05-09T13:16:55","modified_gmt":"2021-05-09T07:46:55","slug":"sas-numeric-format","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/sas-numeric-format\/","title":{"rendered":"SAS Numeric Format &#8211; SAS Informat &amp; Output Format"},"content":{"rendered":"<p>We read in the earlier tutorials that while defining a variable, it is sometimes required that we specify a SAS format for the same.<\/p>\n<p>Today we will be learning about the SAS Numeric Format, types of Numeric Format in <strong>SAS Programming Language<\/strong>: SAS Informat\u00a0and SAS Output Formats.<\/p>\n<p>Moreover, how SAS Numeric format &amp; types of numeric formats used in a program to meet our needs. At last, we will discuss syntax of Informat and output format of SAS Numeric format.<\/p>\n<p>Let&#8217;s\u00a0start with SAS Numeric Format.<\/p>\n<h2>SAS Informat<\/h2>\n<p>SAS informat is one of the components of SAS Numeric Formate, specify how we wish to read a particular data. They are specified in the INPUT statement while defining variables.<\/p>\n<p>A decimal (.) is always placed at the end of the informat and that is how SAS differentiates it from other variables. The informat instructs SAS on how to read data into <strong>SAS variables<\/strong>.<\/p>\n<p>The syntax for a SAS informat is:<br \/>\nVariable_name Format_namew.d<br \/>\nHere:<\/p>\n<ul>\n<li><strong>Variable_name<\/strong>\u00a0is the name of the variable that will be read using the informat.<\/li>\n<li><strong>Format_name<\/strong>\u00a0is the name we wish to give to the informat variable.<\/li>\n<li><strong>w<\/strong>\u00a0is the maximum number of columns that can be stored with the variable.<\/li>\n<li><strong>d<\/strong>\u00a0is the number of digits to the right of the decimal.<\/li>\n<\/ul>\n<p>There are different types of SAS informat\u00a0available depending upon the data type of variable. These are:<\/p>\n<p>SAS Character Informat: $INFORMAT_namew.<br \/>\nSAS\u00a0Numeric Informat: INFORMAT_namew.d<br \/>\nDate\/Time Informat: INFORMAT_namew.<\/p>\n<h2>Reading SAS Numeric Format<\/h2>\n<p>There are two components in a SAS numeric format. The number of columns (width) v of the output and the number of decimal places. The SAS system uses floating-point representation referred to us as W.D, where W is the width and D is the number of digits to the right of the decimal place.<\/p>\n<p>As an example, 8.2 will allocate a total of 8 spaces for the output. One space will be for the decimal and 2 for the digits to the right of the decimal; this will leave 5 spaces for the digits to the left of the decimal.<\/p>\n<p>In the below table, numeric data 12345.66 is demonstrated how to allocate digits and decimal in the SAS system using 8.2 formats.<\/p>\n<table>\n<tbody>\n<tr>\n<td width=\"30\">1<\/td>\n<td width=\"36\">2<\/td>\n<td width=\"30\">3<\/td>\n<td width=\"42\">4<\/td>\n<td width=\"30\">5<\/td>\n<td width=\"30\">.<\/td>\n<td width=\"30\">6<\/td>\n<td width=\"30\">6<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Input SAS Numeric Format (INFORMATS)<\/strong><\/p>\n<table width=\"604\">\n<tbody>\n<tr>\n<td><strong>n.<\/strong><\/td>\n<td>Maximum &#8220;n&#8221; number of columns with no decimal point.<\/td>\n<\/tr>\n<tr>\n<td width=\"92\"><strong>n.p<\/strong><\/td>\n<td>Maximum &#8220;n&#8221; number of columns with &#8220;p&#8221; decimal points.<\/td>\n<\/tr>\n<tr>\n<td><strong>COMMAn.p<\/strong><\/td>\n<td>Maximum &#8220;n&#8221; number of columns with &#8220;p&#8221; decimal places which removes any comma or dollar signs.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>SAS Output Format<\/h2>\n<p>SAS Output Format is an instruction for displaying data in SAS. It is another\u00a0component of SAS Numeric Format.<\/p>\n<p><strong>Example<\/strong> \u2013 If there is a salary column in our dataset, salary being a numeric data type will have decimal places in it. Let the salary be 3467.201.<\/p>\n<p>Now, a person reading this look at this salary in terms of dollars, so we would want to place a dollar sign before it. Like this &#8211; $3467.20. For this, we would have to use an informat to instruct SAS that we want to read this salary in terms of dollars.<\/p>\n<p>Now, consider somebody who reads this as three thousand four hundred and sixty-seven dollars. He would want to have commas after every 3 digits, to get a better understanding. In that case, it would look like this &#8211; $3,467.201<\/p>\n<p>Now, say we want only 2 digits after the decimal, again we would have to specify in the informat the no. of digits we want after the decimal. Example- 3467.20<\/p>\n<p>There are 3 common types of SAS Output formats for displaying numeric data:<\/p>\n<ul>\n<li><strong>Simple W.D format<\/strong>: described in the above example of 8.2 formats. The SAS system writes the number in the total of W spaces, one space for decimal and D spaces for the numbers of decimals.<\/li>\n<li><strong>CommaW.D format<\/strong>: as an example of comma8.2 will allocate a total of 8 spaces for the output. 1 space is allocated for the decimal, 2 spaces for the number of decimals and 1 space for comma as a separator in every 3 digits. The below is an example for the number 1,234.66 using 8.2 formats.<\/li>\n<\/ul>\n<table>\n<tbody>\n<tr>\n<td width=\"30\">1<\/td>\n<td width=\"36\">,<\/td>\n<td width=\"30\">2<\/td>\n<td width=\"42\">3<\/td>\n<td width=\"30\">4<\/td>\n<td width=\"30\">.<\/td>\n<td width=\"30\">6<\/td>\n<td width=\"30\">6<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<ul>\n<li><strong>DollarW.D format<\/strong>: in an example of dollar8.1 will allocate a total of 8 spaces for the output. 1 space is reserved for the decimal, 1 spaces for the number of decimals and 1 spaces for a dollar sign and 1 space for comma as a separator in every 3 digits. Here we display the number $1,234.9 in 8.1 formats.<\/li>\n<\/ul>\n<table>\n<tbody>\n<tr>\n<td width=\"30\">$<\/td>\n<td width=\"36\">1<\/td>\n<td width=\"30\">,<\/td>\n<td width=\"42\">2<\/td>\n<td width=\"30\">3<\/td>\n<td width=\"30\">4<\/td>\n<td width=\"30\">.<\/td>\n<td width=\"30\">9<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>NOTE-<\/strong><br \/>\nWe see that the COMMAw.d informat\u00a0used above has a different function from the COMMAw.d format. SAS informat\u00a0ignores dollar signs and commas while the COMMAw.d format outputs data includes commas but no dollar sign.<\/p>\n<h2>SAS Numeric Format Examples<\/h2>\n<p>At below, we discuss an example of SAS Numeric Format with it&#8217;s output\/result.<\/p>\n<pre class=\"EnlighterJSRAW\">DATA MYDATA1;\r\ninput x 6.; \/*maximuum width of the data*\/\r\nformat x 6.3;\r\ndatalines;\r\n8722\r\n93.2\r\n.1122\r\n15.116\r\nPROC PRINT DATA = MYDATA1;\r\nRUN;\r\nDATA MYDATA2;\r\ninput x 6.; \/*maximum width of the data*\/\r\nformat x 5.2;\r\ndatalines;\r\n8722\r\n93.2\r\n.1122\r\n15.116\r\nPROC PRINT DATA=MYDATA2;\r\nRUN;\r\nDATA MYDATA3;\r\ninput x 6.; \/*maximum width of the data*\/\r\nformat x DOLLAR10.2;\r\ndatalines;\r\n8722\r\n93.2\r\n.1122\r\n15.116\r\nPROC PRINT DATA=MYDATA3;\r\nRUN;<\/pre>\n<p><strong>Output<\/strong><br \/>\n# MYDATA1.<br \/>\nObs \u00a0\u00a0\u00a0 x<br \/>\n1 \u00a0\u00a0\u00a0\u00a0\u00a0 8722.0 # Display 6 columns with zero appended after a\u00a0decimal.<br \/>\n2 \u00a0\u00a0\u00a0\u00a0\u00a0 93.200 # Display 6 columns with zero appended after a\u00a0decimal.<br \/>\n3 \u00a0\u00a0\u00a0\u00a0\u00a0 0.112\u00a0 # No integers before a\u00a0decimal, so display 3 available digits after a\u00a0decimal.<br \/>\n4 \u00a0\u00a0\u00a0\u00a0\u00a0 15.116 # Display 6 columns with 3 available digits after a decimal.<\/p>\n<p># MYDATA2<br \/>\nObs \u00a0\u00a0\u00a0 x<br \/>\n1 \u00a0\u00a0\u00a0\u00a0\u00a0 8722\u00a0 # Display 5 columns. Only 4 are available.<br \/>\n2 \u00a0\u00a0\u00a0\u00a0\u00a0 93.20 # Display 5 columns with zero appended after a\u00a0decimal.<br \/>\n3 \u00a0\u00a0\u00a0\u00a0\u00a0 0.11\u00a0 # Display 5 columns with 2 places after a\u00a0decimal.<br \/>\n4 \u00a0\u00a0\u00a0\u00a0\u00a0 15.12 # Display 5 columns with 2 places after a\u00a0decimal.<\/p>\n<p># MYDATA3<br \/>\nObs \u00a0\u00a0\u00a0 x<br \/>\n1 \u00a0\u00a0\u00a0\u00a0\u00a0 $8,722.00 # Display 10 columns with leading $ sign, a comma at a thousandth place and zeros appended after the decimal.<br \/>\n2 \u00a0\u00a0\u00a0\u00a0\u00a0 $93.20\u00a0\u00a0\u00a0 # Only 2 integers available before decimal and one available after the decimal.<br \/>\n3 \u00a0\u00a0\u00a0\u00a0\u00a0 $0.11\u00a0\u00a0 \u00a0 # No integers available before decimal and two available after the decimal.<br \/>\n4 \u00a0\u00a0\u00a0\u00a0\u00a0 $15.12\u00a0\u00a0\u00a0 # Only 2 integers available before decimal and two available after a decimal<\/p>\n<h2>Conclusion<\/h2>\n<p>Hence, today we discovered some great ways of reading SAS numeric Format by specifying SAS Informat and SAS Output format. So, that we get our data the way we want it too. Wasn\u2019t this interesting? You can post your doubts and queries in the comments section below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We read in the earlier tutorials that while defining a variable, it is sometimes required that we specify a SAS format for the same. Today we will be learning about the SAS Numeric Format,&#46;&#46;&#46;<\/p>\n","protected":false},"author":6,"featured_media":11454,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[59],"tags":[1167,9164,9165,11384,12027,12028,12052,12093,12110],"class_list":["post-11388","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-sas","tag-as-numeric-format-examples","tag-numeric-formate","tag-numeric-formate-in-sas","tag-reading-sas-numeric-format","tag-sas-format","tag-sas-formate","tag-sas-informat","tag-sas-numeric-formate","tag-sas-output-format"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>SAS Numeric Format - SAS Informat &amp; Output Format - DataFlair<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/sas-numeric-format\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SAS Numeric Format - SAS Informat &amp; Output Format - DataFlair\" \/>\n<meta property=\"og:description\" content=\"We read in the earlier tutorials that while defining a variable, it is sometimes required that we specify a SAS format for the same. Today we will be learning about the SAS Numeric Format,&#046;&#046;&#046;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/sas-numeric-format\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-03-22T07:31:26+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-05-09T07:46:55+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/03\/SAS-Numeric-Format-01.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"SAS Numeric Format - SAS Informat &amp; Output Format - DataFlair","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/sas-numeric-format\/","og_locale":"en_US","og_type":"article","og_title":"SAS Numeric Format - SAS Informat &amp; Output Format - DataFlair","og_description":"We read in the earlier tutorials that while defining a variable, it is sometimes required that we specify a SAS format for the same. Today we will be learning about the SAS Numeric Format,&#46;&#46;&#46;","og_url":"https:\/\/data-flair.training\/blogs\/sas-numeric-format\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2018-03-22T07:31:26+00:00","article_modified_time":"2021-05-09T07:46:55+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/03\/SAS-Numeric-Format-01.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/sas-numeric-format\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/sas-numeric-format\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/2c58ecb4f73a39f0ef993f1ddfcd7b89"},"headline":"SAS Numeric Format &#8211; SAS Informat &amp; Output Format","datePublished":"2018-03-22T07:31:26+00:00","dateModified":"2021-05-09T07:46:55+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/sas-numeric-format\/"},"wordCount":968,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/sas-numeric-format\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/03\/SAS-Numeric-Format-01.jpg","keywords":["AS Numeric Format Examples","numeric formate","Numeric Formate in SAS","Reading SAS Numeric Format","SAS Format","SAS Formate","SAS Informat","SAS Numeric Formate","SAS Output Format"],"articleSection":["SAS Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/sas-numeric-format\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/sas-numeric-format\/","url":"https:\/\/data-flair.training\/blogs\/sas-numeric-format\/","name":"SAS Numeric Format - SAS Informat &amp; Output Format - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/sas-numeric-format\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/sas-numeric-format\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/03\/SAS-Numeric-Format-01.jpg","datePublished":"2018-03-22T07:31:26+00:00","dateModified":"2021-05-09T07:46:55+00:00","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/sas-numeric-format\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/sas-numeric-format\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/sas-numeric-format\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/03\/SAS-Numeric-Format-01.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/03\/SAS-Numeric-Format-01.jpg","width":1200,"height":628,"caption":"Types of SAS Numeric Format"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/sas-numeric-format\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"garbage collection algorithm in data structure","item":"https:\/\/data-flair.training\/blogs\/tag\/garbage-collection-algorithm-in-data-structure\/"},{"@type":"ListItem","position":3,"name":"SAS Numeric Format &#8211; SAS Informat &amp; Output Format"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/2c58ecb4f73a39f0ef993f1ddfcd7b89","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"The DataFlair Team provides industry-driven content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our expert educators focus on delivering value-packed, easy-to-follow resources for tech enthusiasts and professionals.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam2\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/11388","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=11388"}],"version-history":[{"count":5,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/11388\/revisions"}],"predecessor-version":[{"id":93957,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/11388\/revisions\/93957"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/11454"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=11388"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=11388"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=11388"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}