{"id":195716,"date":"2025-02-28T16:00:29","date_gmt":"2025-02-28T16:00:29","guid":{"rendered":"https:\/\/learnexams.com\/blog\/?p=195716"},"modified":"2025-02-28T16:00:33","modified_gmt":"2025-02-28T16:00:33","slug":"starting-with-the-sashelp-data-set-sales-create-a-temporary-sas-data-set-call-it-sales-that-contains-a-variable-call-it-date-that-is-a-sas-date-by-using-the-three-variables-month-day-and-year","status":"publish","type":"post","link":"https:\/\/www.learnexams.com\/blog\/2025\/02\/28\/starting-with-the-sashelp-data-set-sales-create-a-temporary-sas-data-set-call-it-sales-that-contains-a-variable-call-it-date-that-is-a-sas-date-by-using-the-three-variables-month-day-and-year\/","title":{"rendered":"Starting with the SASHelp data set, Sales, create a temporary SAS data set (call it Sales) that contains a variable (call it Date) that is a SAS date by using the three variables Month, Day, and Year (remember the MDY function)"},"content":{"rendered":"\n<p>Starting with the SASHelp data set, Sales, create a temporary SAS data set (call it Sales) that contains a variable (call it Date) that is a SAS date by using the three variables Month, Day, and Year (remember the MDY function). Be aware that the original SASHelp data set also contains a variable called Date, but it is not a SAS date. You can drop the original Date variable with a DROP= data set option on the SET statement when you bring in data from the SASHelp data set. Next, generate a time series plot with Date on the x axis and Sales on the y axis. It should look like this:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/learnexams.com\/blog\/wp-content\/uploads\/2025\/02\/image-1712.png\" alt=\"\" class=\"wp-image-195717\"\/><\/figure>\n\n\n\n<p><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-ast-global-color-6-color\"><strong>The Correct Answer and Explanation is :<\/strong><\/mark><\/p>\n\n\n\n<p>To create a temporary SAS data set named <code>Sales<\/code> that includes a SAS date variable derived from the existing <code>Month<\/code>, <code>Day<\/code>, and <code>Year<\/code> variables, and then generate a time series plot with <code>Date<\/code> on the x-axis and <code>Sales<\/code> on the y-axis, follow these steps:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Create the <code>Sales<\/code> Data Set with a SAS Date Variable:<\/strong> Use the <code>MDY<\/code> function to combine the <code>Month<\/code>, <code>Day<\/code>, and <code>Year<\/code> variables into a new variable <code>Date<\/code>. The <code>MDY<\/code> function returns a SAS date value from the specified month, day, and year. \ue200cite\ue202turn0search2\ue201<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>   data Sales;\n       set sashelp.sales(drop=Date);\n       Date = mdy(Month, Day, Year);\n       format Date date9.;\n   run;<\/code><\/pre>\n\n\n\n<p>In this code:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>set sashelp.sales(drop=Date);<\/code> reads the <code>sashelp.sales<\/code> data set and drops the existing <code>Date<\/code> variable to avoid conflicts.<\/li>\n\n\n\n<li><code>Date = mdy(Month, Day, Year);<\/code> creates a new <code>Date<\/code> variable by combining <code>Month<\/code>, <code>Day<\/code>, and <code>Year<\/code>.<\/li>\n\n\n\n<li><code>format Date date9.;<\/code> formats the <code>Date<\/code> variable to display in the <code>date9.<\/code> format (e.g., 28FEB2025).<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Generate the Time Series Plot:<\/strong> Use the <code>SGPLOT<\/code> procedure to create a time series plot with <code>Date<\/code> on the x-axis and <code>Sales<\/code> on the y-axis. The <code>series<\/code> statement plots the data points connected by lines, which is suitable for time series data. \ue200cite\ue202turn0search1\ue201<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>   proc sgplot data=Sales;\n       series x=Date y=Sales;\n       xaxis label='Date';\n       yaxis label='Sales';\n   run;<\/code><\/pre>\n\n\n\n<p>In this code:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>proc sgplot data=Sales;<\/code> initiates the plotting procedure using the <code>Sales<\/code> data set.<\/li>\n\n\n\n<li><code>series x=Date y=Sales;<\/code> plots the <code>Sales<\/code> variable against <code>Date<\/code>, connecting the points with lines.<\/li>\n\n\n\n<li><code>xaxis label='Date';<\/code> and <code>yaxis label='Sales';<\/code> add labels to the x-axis and y-axis, respectively.<\/li>\n<\/ul>\n\n\n\n<p><strong>Explanation:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>MDY Function:<\/strong> The <code>MDY<\/code> function in SAS is used to create a SAS date value from separate month, day, and year variables. It takes three arguments: month, day, and year, and returns a SAS date value representing that specific date. For example, <code>mdy(2, 28, 2025)<\/code> returns the SAS date value for February 28, 2025. \ue200cite\ue202turn0search2\ue201<\/li>\n\n\n\n<li><strong>SAS Date Values:<\/strong> SAS stores dates as the number of days since January 1, 1960. This internal representation allows for efficient date calculations and comparisons. When you create a date variable using the <code>MDY<\/code> function, SAS assigns it this numeric value, which can be formatted for display purposes.<\/li>\n\n\n\n<li><strong>Time Series Plot:<\/strong> The <code>SGPLOT<\/code> procedure is a versatile tool in SAS for creating various types of plots, including time series plots. The <code>series<\/code> statement is specifically designed for time series data, as it connects data points with lines, making it easier to visualize trends over time. The <code>xaxis<\/code> and <code>yaxis<\/code> statements allow you to customize the labels of the axes for better clarity. \ue200cite\ue202turn0search1\ue201<\/li>\n<\/ul>\n\n\n\n<p>By following these steps, you can effectively create a new date variable from existing components and visualize the sales data over time using a time series plot in SAS.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Starting with the SASHelp data set, Sales, create a temporary SAS data set (call it Sales) that contains a variable (call it Date) that is a SAS date by using the three variables Month, Day, and Year (remember the MDY function). Be aware that the original SASHelp data set also contains a variable called Date, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[25],"tags":[],"class_list":["post-195716","post","type-post","status-publish","format-standard","hentry","category-exams-certification"],"_links":{"self":[{"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/posts\/195716","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/comments?post=195716"}],"version-history":[{"count":0,"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/posts\/195716\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/media?parent=195716"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/categories?post=195716"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/tags?post=195716"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}