

{"id":12994,"date":"2018-04-10T11:45:40","date_gmt":"2018-04-10T06:15:40","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=12994"},"modified":"2021-05-09T13:16:01","modified_gmt":"2021-05-09T07:46:01","slug":"variables-in-sas","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/variables-in-sas\/","title":{"rendered":"FIRST. and LAST. Variables in SAS &#8211; How to Select the Variables"},"content":{"rendered":"<p>Previously, we have seen the <strong><a href=\"https:\/\/data-flair.training\/blogs\/sas-variable\/\">SAS variable<\/a><\/strong>, today we will be looking at the use of FIRST. and LAST. variable in SAS Programming Language. We will discuss the working of\u00a0FIRST. and LAST. Variables in SAS and how to select SAS FIRST. Variable. At last, we will study how to select LAST. variables in SAS and calculate the cumulative score by the group.<\/p>\n<p>So, let&#8217;s start with the FIRST. and LAST. Variables in SAS.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/FIRST.-LAST.-in-SAS-01-1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-13022 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/FIRST.-LAST.-in-SAS-01-1.jpg\" alt=\"FIRST. and LAST. Variables in SAS - Data Step Processing in By Groups\" width=\"1200\" height=\"628\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/FIRST.-LAST.-in-SAS-01-1.jpg 1200w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/FIRST.-LAST.-in-SAS-01-1-150x79.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/FIRST.-LAST.-in-SAS-01-1-300x157.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/FIRST.-LAST.-in-SAS-01-1-768x402.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/FIRST.-LAST.-in-SAS-01-1-1024x536.jpg 1024w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/a><\/p>\n<h2>What is FIRST. &amp; LAST. Variables in SAS?<\/h2>\n<p>Anytime we wish to group our data in SAS Programming, we make use of the BY statement to tell the order of grouping and the SET statement to group data. Whenever both BY and SET statements are used together, SAS automatically creates two variables, FIRST. and LAST. Variables in SAS, that are temporary.<\/p>\n<p>SAS uses the value of the FIRST. and LAST. Variables to identify the first and last observations in a group. <a href=\"https:\/\/en.wikipedia.org\/wiki\/SAS\">SAS<\/a> places FIRST. and LAST. Variable in <strong>SAS Program Data Vector (PDV).<\/strong> Then, they are available for DATA step processing but SAS does not add them to the output data set as\u00a0they are temporary in nature.<\/p>\n<p><strong>Explore the concept &#8211; <a href=\"https:\/\/data-flair.training\/blogs\/sas-macro\/\">SAS Macro For Beginners<\/a><\/strong><\/p>\n<h2>How FIRST. and LAST. Variables Works<\/h2>\n<p>When an observation is the first in a BY group, SAS sets the value of FIRST.<em>variable<\/em>\u00a0to 1 for the variable whose value changed, as well as for all of the variables that follow in the BY statement. For all other observations in the BY group, the value of FIRST.<em>variable<\/em>\u00a0is 0.<\/p>\n<p>Likewise, if the observation is the last in a BY group, SAS sets the value of LAST.<em>variable\u00a0<\/em>to 1 for the variable whose value changes on the next observation, as well as for all the variables that follow in the BY statement. For all other observations in the BY group, the value of LAST.<em>variable<\/em>\u00a0is 0. For the last observation in a data set, the value of all LAST.<em>variable<\/em>\u00a0variables are set to 1.<\/p>\n<p>The values of both FIRST. and LAST. variables in SAS are either 1 or 0.<\/p>\n<ul>\n<li>FIRST.<em>variable<\/em>\u00a0= 1, when an observation is the first observation in a BY group.<\/li>\n<li>FIRST.<em>variable<\/em>\u00a0= 0, when an observation is not the first observation in a BY group.<\/li>\n<li>LAST.<em>variable<\/em>\u00a0= 1, when an observation is the last observation in a BY group.<\/li>\n<li>LAST.<em>variable<\/em>\u00a0= 0, when an observation is not the last observation in a BY group.<\/li>\n<\/ul>\n<p><strong>Example of FIRST. and LAST. Variables in SAS\u00a0&#8211;<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\">data class1;\r\ninput ID Name $ Marks;\r\ncards;\r\n1\u00a0\u00a0\u00a0\u00a0 Rahul\u00a0\u00a0   45\r\n1\u00a0\u00a0\u00a0\u00a0 Ajay\u00a0\u00a0\u00a0   74\r\n2\u00a0\u00a0\u00a0\u00a0 Ram\u00a0\u00a0\u00a0\u00a0   45\r\n2\u00a0\u00a0\u00a0\u00a0 Girish\u00a0   54\r\n3\u00a0\u00a0\u00a0\u00a0 Simran\u00a0   87\r\n3\u00a0\u00a0\u00a0\u00a0 Priya\u00a0\u00a0   92\r\n3\u00a0\u00a0\u00a0\u00a0 Riya\u00a0\u00a0\u00a0   87\r\n4\u00a0\u00a0\u00a0\u00a0 Tina\u00a0\u00a0\u00a0   23\r\n5\u00a0\u00a0\u00a0\u00a0 Dave\u00a0\u00a0\u00a0   87\r\n5\u00a0\u00a0\u00a0\u00a0 Ken\u00a0\u00a0\u00a0\u00a0   87\r\n6\u00a0\u00a0\u00a0\u00a0 Albert\u00a0   63\r\n8\u00a0\u00a0\u00a0\u00a0 Alex\u00a0\u00a0\u00a0   72\r\n;\r\nrun;<\/pre>\n<pre class=\"EnlighterJSRAW\">PROC SORT DATA = class1;\r\nBY ID;\r\nRUN;<\/pre>\n<pre class=\"EnlighterJSRAW\">DATA class2;\r\nSET class1;\r\nBY ID;\r\nFirst_ID= First.ID;\r\nLast_ID= Last.ID;\r\nRUN;<\/pre>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/output-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-13001 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/output-1.png\" alt=\"Example of FIRST. and LAST. Variables in SAS\" width=\"1319\" height=\"440\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/output-1.png 1319w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/output-1-150x50.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/output-1-300x100.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/output-1-768x256.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/output-1-1024x342.png 1024w\" sizes=\"auto, (max-width: 1319px) 100vw, 1319px\" \/><\/a><\/p>\n<p>We used\u00a0PROC SORT\u00a0to sort the data, set by ID. It is required to sort the data before using first. and last. variables.<\/p>\n<p>FIRST.\/LAST.\u00a0variables are\u00a0temporary variables. That means they are not visible in the newly created data set. To make them visible, we need to create two new variables. In the program above, i have created First_ID and Last_ID variables.<\/p>\n<p><strong>Have a look at the\u00a0<a href=\"https:\/\/data-flair.training\/blogs\/sas-proc-sort\/\">SAS Proc Sort Procedure\u00a0<\/a><\/strong><\/p>\n<h2>Selecting FIRST. Variable in SAS<\/h2>\n<p>Suppose you need to select only the first observation among a group of observations. It is very easy to do it with IF statement. The IF statement subsets data when IF is not used in conjunction with THEN or ELSE statements.<\/p>\n<p><strong>Example of FIRST. Variable in SAS-<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\">PROC SORT DATA = class1;\r\nBY ID;\r\nRUN;<\/pre>\n<pre class=\"EnlighterJSRAW\">DATA class2;\r\nSET READIN;\r\nBY ID;\r\nIF FIRST.ID;\r\nPROC PRINT;\r\nRUN;<\/pre>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/output-2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-13002 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/output-2.png\" alt=\"Example of First. Variable in SAS\" width=\"680\" height=\"360\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/output-2.png 680w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/output-2-150x79.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/output-2-300x159.png 300w\" sizes=\"auto, (max-width: 680px) 100vw, 680px\" \/><\/a><\/p>\n<p>It returns first observation among values of a group (total 7 observations).<\/p>\n<h2>Selecting Last. Variable in SAS<\/h2>\n<p>Suppose you are asked to include only last observation from a group. Like the previous example, we can use last. variable to subset data.<br \/>\n<strong>Example of Last. Variable in SAS-<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\">PROC SORT DATA = class1;\r\nBY ID;\r\nRUN;<\/pre>\n<pre class=\"EnlighterJSRAW\">DATA class2;\r\nSET READIN;\r\nBY ID;\r\nIF LAST.ID;\r\nPROC PRINT;\r\nRUN;<\/pre>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/OUTPUT-3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-13003 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/OUTPUT-3.png\" alt=\"Selecting Last. Variable in SAS\" width=\"621\" height=\"355\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/OUTPUT-3.png 621w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/OUTPUT-3-150x86.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/OUTPUT-3-300x171.png 300w\" sizes=\"auto, (max-width: 621px) 100vw, 621px\" \/><\/a><\/p>\n<p><strong>Have you checked? &#8211; <a href=\"https:\/\/data-flair.training\/blogs\/sas-sql\/\">PROC SQL SAS Guide<\/a><\/strong><\/p>\n<h2>How to calculate Cumulative Score in BY Group<\/h2>\n<p>Suppose you need to calculate cumulative score by variable ID.<\/p>\n<p><strong>Example of Cumulative Score-<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\">Data class3;\r\nset class1;\r\nby ID;\r\nif first.id then CumScore = Marks;\r\nelse CumScore + Marks;\r\nproc print;\r\nrun;<\/pre>\n<p>In the above program, we are setting\u00a0Cumscore = Marks when it is the first value of a group i.e. ID. On the other hand, adding Marks to Cumscore:<\/p>\n<p>The Cumscore+Maarks implies\u00a0CumScore = CumScore + Marks\u00a0in BY group processing.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/output-4.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-13004 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/output-4.png\" alt=\"Calculate Cumulative Score by Group\" width=\"885\" height=\"475\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/output-4.png 885w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/output-4-150x81.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/output-4-300x161.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/output-4-768x412.png 768w\" sizes=\"auto, (max-width: 885px) 100vw, 885px\" \/><\/a><\/p>\n<p>This was all about FIRST. and LAST. Variables in SAS.<\/p>\n<h2>Summary<\/h2>\n<p>We hope you enjoyed this SAS tutorial. Now, you will now be able to efficiently use FIRST. And LAST. variables in SAS.<\/p>\n<p>Any queries or feedback? Feel free to enter in the comment section.<\/p>\n<p><b>Start a career in SAS technology by acquiring <a href=\"https:\/\/data-flair.training\/blogs\/sas-certification\/\">SAS certifications<\/a>.<\/b><span hidden class=\"__iawmlf-post-loop-links\" data-iawmlf-links=\"[{&quot;id&quot;:1994,&quot;href&quot;:&quot;https:\\\/\\\/en.wikipedia.org\\\/wiki\\\/SAS&quot;,&quot;archived_href&quot;:&quot;http:\\\/\\\/web-wp.archive.org\\\/web\\\/20251210160241\\\/https:\\\/\\\/en.wikipedia.org\\\/wiki\\\/SAS&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2025-12-11 08:32:40&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2025-12-14 23:49:12&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2025-12-18 20:33:49&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2025-12-22 06:10:10&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2025-12-25 14:41:07&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2025-12-29 12:21:32&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-01 20:36:41&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-05 09:39:01&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-09 21:41:04&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-13 13:26:58&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-20 10:59:33&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-25 17:06:45&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-29 15:42:29&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-02 15:33:47&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-06 14:17:11&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-10 10:40:34&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-13 19:40:19&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-17 07:09:34&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-20 11:21:21&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-24 02:28:53&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-27 09:37:21&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-02 13:37:28&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-05 17:31:32&quot;,&quot;http_code&quot;:429},{&quot;date&quot;:&quot;2026-03-09 11:03:40&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-12 18:32:08&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-18 04:27:18&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-23 13:20:56&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-27 08:15:30&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-30 21:31:03&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-03 05:56:48&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-06 18:57:19&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-10 06:13:45&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-13 23:18:16&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-16 23:22:29&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-20 13:01:26&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-23 15:55:08&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-04-28 07:28:45&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-01 11:31:44&quot;,&quot;http_code&quot;:429},{&quot;date&quot;:&quot;2026-05-04 14:03:09&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-07 14:47:58&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-12 19:31:57&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-18 15:49:14&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-23 19:54:56&quot;,&quot;http_code&quot;:429},{&quot;date&quot;:&quot;2026-05-27 21:08:31&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-06-01 17:36:03&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-06-04 23:21:46&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-06-08 04:47:14&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-06-15 04:03:32&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-06-18 12:10:36&quot;,&quot;http_code&quot;:200}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-06-18 12:10:36&quot;,&quot;http_code&quot;:200},&quot;process&quot;:&quot;done&quot;}]\"><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Previously, we have seen the SAS variable, today we will be looking at the use of FIRST. and LAST. variable in SAS Programming Language. We will discuss the working of\u00a0FIRST. and LAST. Variables in&#46;&#46;&#46;<\/p>\n","protected":false},"author":6,"featured_media":13022,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[59],"tags":[3465,4719,11992,15344],"class_list":["post-12994","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-sas","tag-data-step-processing","tag-first-and-last-variables-in-sas","tag-sas-data-step-processing","tag-variables-in-sas"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>FIRST. and LAST. Variables in SAS - How to Select the Variables - DataFlair<\/title>\n<meta name=\"description\" content=\"FIRST. and LAST. Variables in SAS tutorial covers working of variables, selecting variables and calculating cumulative score in BY group.\" \/>\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\/variables-in-sas\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"FIRST. and LAST. Variables in SAS - How to Select the Variables - DataFlair\" \/>\n<meta property=\"og:description\" content=\"FIRST. and LAST. Variables in SAS tutorial covers working of variables, selecting variables and calculating cumulative score in BY group.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/variables-in-sas\/\" \/>\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-04-10T06:15:40+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-05-09T07:46:01+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/FIRST.-LAST.-in-SAS-01-1.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=\"4 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"FIRST. and LAST. Variables in SAS - How to Select the Variables - DataFlair","description":"FIRST. and LAST. Variables in SAS tutorial covers working of variables, selecting variables and calculating cumulative score in BY group.","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\/variables-in-sas\/","og_locale":"en_US","og_type":"article","og_title":"FIRST. and LAST. Variables in SAS - How to Select the Variables - DataFlair","og_description":"FIRST. and LAST. Variables in SAS tutorial covers working of variables, selecting variables and calculating cumulative score in BY group.","og_url":"https:\/\/data-flair.training\/blogs\/variables-in-sas\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2018-04-10T06:15:40+00:00","article_modified_time":"2021-05-09T07:46:01+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/FIRST.-LAST.-in-SAS-01-1.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":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/variables-in-sas\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/variables-in-sas\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/2c58ecb4f73a39f0ef993f1ddfcd7b89"},"headline":"FIRST. and LAST. Variables in SAS &#8211; How to Select the Variables","datePublished":"2018-04-10T06:15:40+00:00","dateModified":"2021-05-09T07:46:01+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/variables-in-sas\/"},"wordCount":719,"commentCount":2,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/variables-in-sas\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/FIRST.-LAST.-in-SAS-01-1.jpg","keywords":["Data Step Processing","FIRST. and LAST. Variables in SAS","SAS Data Step Processing","Variables in SAS"],"articleSection":["SAS Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/variables-in-sas\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/variables-in-sas\/","url":"https:\/\/data-flair.training\/blogs\/variables-in-sas\/","name":"FIRST. and LAST. Variables in SAS - How to Select the Variables - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/variables-in-sas\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/variables-in-sas\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/FIRST.-LAST.-in-SAS-01-1.jpg","datePublished":"2018-04-10T06:15:40+00:00","dateModified":"2021-05-09T07:46:01+00:00","description":"FIRST. and LAST. Variables in SAS tutorial covers working of variables, selecting variables and calculating cumulative score in BY group.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/variables-in-sas\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/variables-in-sas\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/variables-in-sas\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/FIRST.-LAST.-in-SAS-01-1.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/FIRST.-LAST.-in-SAS-01-1.jpg","width":1200,"height":628,"caption":"FIRST. and LAST. Variables in SAS - Data Step Processing in By Groups"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/variables-in-sas\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"SAS Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/sas\/"},{"@type":"ListItem","position":3,"name":"FIRST. and LAST. Variables in SAS &#8211; How to Select the Variables"}]},{"@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\/12994","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=12994"}],"version-history":[{"count":8,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/12994\/revisions"}],"predecessor-version":[{"id":55329,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/12994\/revisions\/55329"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/13022"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=12994"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=12994"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=12994"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}