<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Base sas in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Base-sas/m-p/764339#M242092</link>
    <description>&lt;P&gt;Before we change the input data, let's first run my suggested DATA step on your original data&amp;nbsp;and a PROC PRINT step to show dataset WANT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Log:&lt;/P&gt;
&lt;PRE&gt;11   data want;
12   update ds(obs=0) ds;
13   by id;
14   run;

NOTE: There were 0 observations read from the data set WORK.DS.
NOTE: There were 4 observations read from the data set WORK.DS.
NOTE: The data set WORK.WANT has 2 observations and 3 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


15
16   proc print data=want noobs;
17   run;

NOTE: There were 2 observations read from the data set WORK.WANT.
NOTE: PROCEDURE PRINT used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds&lt;/PRE&gt;
&lt;P&gt;Output:&lt;/P&gt;
&lt;PRE&gt; id      date1        date2

100    10Jun2020    10Jul2021
101    10Jun2021    10May2021&lt;/PRE&gt;
&lt;P&gt;Now compare this to the "output required":&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/393418"&gt;@u59166072&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;output required:&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;id date1 date2&lt;BR /&gt;100 10Jun2020 10Jul2021&lt;BR /&gt;101 10Jun2021 10May2021&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Using the new data (copied into your DATA step) ...&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ds;
infile datalines;
input id date1: $10. date2: $10.;
datalines;
101 10Jun2020 .
101 . 11July2021
102 30May2020 .
102 . 10May2021
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;... the log looks the same and the output is:&lt;/P&gt;
&lt;PRE&gt; id      date1        date2

101    10Jun2020    11July2021
102    30May2020    10May2021&lt;/PRE&gt;</description>
    <pubDate>Thu, 26 Aug 2021 20:41:05 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2021-08-26T20:41:05Z</dc:date>
    <item>
      <title>Base sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Base-sas/m-p/764311#M242078</link>
      <description>&lt;P&gt;Dear Team,&lt;/P&gt;&lt;P&gt;Please provide the output like for this data.&lt;/P&gt;&lt;P&gt;data ds;&lt;BR /&gt;infile datalines;&lt;BR /&gt;input id date1: $10. date2: $10.;&lt;BR /&gt;datalines;&lt;BR /&gt;100 10Jun2020 .&lt;BR /&gt;100 . 10Jul2021&lt;BR /&gt;101 10Jun2021 .&lt;BR /&gt;101 . 10May2021&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;output required:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;id date1 date2&lt;BR /&gt;100 10Jun2020 10Jul2021&lt;BR /&gt;101 10Jun2021 10May2021&lt;/P&gt;</description>
      <pubDate>Thu, 26 Aug 2021 19:19:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Base-sas/m-p/764311#M242078</guid>
      <dc:creator>u59166072</dc:creator>
      <dc:date>2021-08-26T19:19:41Z</dc:date>
    </item>
    <item>
      <title>Re: Base sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Base-sas/m-p/764321#M242081</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/393418"&gt;@u59166072&lt;/a&gt;&amp;nbsp;and welcome to the SAS Support Communities!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/p18w3br45er2qun1r8sfmm4grjyr.htm" target="_blank" rel="noopener"&gt;UPDATE statement&lt;/A&gt;:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
update ds(obs=0) ds;
by id;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 26 Aug 2021 19:55:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Base-sas/m-p/764321#M242081</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-08-26T19:55:34Z</dc:date>
    </item>
    <item>
      <title>Re: Base sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Base-sas/m-p/764325#M242084</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
  select
    id,
    max(date1) as date1 format=date9.,
    max(date2) as date2 format=date9.
  from ds
  group by id
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=ds;
by id;
var date1 date2
output out=want (drop=_:) max()=;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 26 Aug 2021 20:01:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Base-sas/m-p/764325#M242084</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-08-26T20:01:28Z</dc:date>
    </item>
    <item>
      <title>Re: Base sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Base-sas/m-p/764333#M242088</link>
      <description>There is no data found the variables to date1 and date2. Please help me in this.&lt;BR /&gt;data below:&lt;BR /&gt;&lt;BR /&gt;101 10Jun2020 .&lt;BR /&gt;101 . 11July2021&lt;BR /&gt;102 30May2020 .&lt;BR /&gt;102 . 10May2021&lt;BR /&gt;</description>
      <pubDate>Thu, 26 Aug 2021 20:21:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Base-sas/m-p/764333#M242088</guid>
      <dc:creator>u59166072</dc:creator>
      <dc:date>2021-08-26T20:21:46Z</dc:date>
    </item>
    <item>
      <title>Re: Base sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Base-sas/m-p/764339#M242092</link>
      <description>&lt;P&gt;Before we change the input data, let's first run my suggested DATA step on your original data&amp;nbsp;and a PROC PRINT step to show dataset WANT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Log:&lt;/P&gt;
&lt;PRE&gt;11   data want;
12   update ds(obs=0) ds;
13   by id;
14   run;

NOTE: There were 0 observations read from the data set WORK.DS.
NOTE: There were 4 observations read from the data set WORK.DS.
NOTE: The data set WORK.WANT has 2 observations and 3 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


15
16   proc print data=want noobs;
17   run;

NOTE: There were 2 observations read from the data set WORK.WANT.
NOTE: PROCEDURE PRINT used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds&lt;/PRE&gt;
&lt;P&gt;Output:&lt;/P&gt;
&lt;PRE&gt; id      date1        date2

100    10Jun2020    10Jul2021
101    10Jun2021    10May2021&lt;/PRE&gt;
&lt;P&gt;Now compare this to the "output required":&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/393418"&gt;@u59166072&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;output required:&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;id date1 date2&lt;BR /&gt;100 10Jun2020 10Jul2021&lt;BR /&gt;101 10Jun2021 10May2021&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Using the new data (copied into your DATA step) ...&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ds;
infile datalines;
input id date1: $10. date2: $10.;
datalines;
101 10Jun2020 .
101 . 11July2021
102 30May2020 .
102 . 10May2021
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;... the log looks the same and the output is:&lt;/P&gt;
&lt;PRE&gt; id      date1        date2

101    10Jun2020    11July2021
102    30May2020    10May2021&lt;/PRE&gt;</description>
      <pubDate>Thu, 26 Aug 2021 20:41:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Base-sas/m-p/764339#M242092</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-08-26T20:41:05Z</dc:date>
    </item>
    <item>
      <title>Re: Base sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Base-sas/m-p/764341#M242093</link>
      <description>could you plz explain me in detail.&lt;BR /&gt;</description>
      <pubDate>Thu, 26 Aug 2021 20:49:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Base-sas/m-p/764341#M242093</guid>
      <dc:creator>u59166072</dc:creator>
      <dc:date>2021-08-26T20:49:11Z</dc:date>
    </item>
    <item>
      <title>Re: Base sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Base-sas/m-p/764344#M242096</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/393418"&gt;@u59166072&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Dear Team,&lt;/P&gt;
&lt;P&gt;Please provide the output like for this data.&lt;/P&gt;
&lt;P&gt;data ds;&lt;BR /&gt;infile datalines;&lt;BR /&gt;input id date1: $10. date2: $10.;&lt;BR /&gt;datalines;&lt;BR /&gt;100 10Jun2020 .&lt;BR /&gt;100 . 10Jul2021&lt;BR /&gt;101 10Jun2021 .&lt;BR /&gt;101 . 10May2021&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;output required:&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;id date1 date2&lt;BR /&gt;100 10Jun2020 10Jul2021&lt;BR /&gt;101 10Jun2021 10May2021&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Generic comment on dates: "Date" values as character, as you do above, almost always leads to extra work if you ever expect to use the values.&lt;/P&gt;
&lt;P&gt;Character values do not sort properly&amp;nbsp; 10Jul2021 will come before 01Jan2021 for example.&lt;/P&gt;
&lt;P&gt;All of the functions that let you do things like check if a date is less than, greater than or between one or more dates won't work.&lt;/P&gt;
&lt;P&gt;The Formats that allow you to create groups of related values such as Month of the year, Month and Year, Year and calendar quarter and such won't work either. Which means you may have to spend a lot of time adding additional not needed variables than if they were proper date values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354&lt;/A&gt; has a PDF with much information about dates.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Aug 2021 20:57:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Base-sas/m-p/764344#M242096</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-08-26T20:57:35Z</dc:date>
    </item>
    <item>
      <title>Re: Base sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Base-sas/m-p/764352#M242103</link>
      <description>&lt;P&gt;The first dataset in the UPDATE statement, &lt;FONT face="courier new,courier"&gt;ds(obs=0)&lt;/FONT&gt;, is an empty (zero-observation) version of the dataset &lt;FONT face="courier new,courier"&gt;ds&lt;/FONT&gt;, i.e., it has all the &lt;EM&gt;variables&lt;/EM&gt;, but does not contain any &lt;EM&gt;values&lt;/EM&gt;. It is used as the "&lt;EM&gt;master file&lt;/EM&gt;" (as it is called in the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/p18w3br45er2qun1r8sfmm4grjyr.htm" target="_blank" rel="noopener"&gt;documentation&lt;/A&gt;). The second&amp;nbsp;dataset in the UPDATE statement, &lt;FONT face="courier new,courier"&gt;ds&lt;/FONT&gt;, i.e., the full version of your input data with four observations containing missing or non-missing values of the variables, serves as the "&lt;EM&gt;transaction dataset&lt;/EM&gt;" in the update process.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This means: For each BY group (i.e., group of observations with the same value of variable &lt;FONT face="courier new,courier"&gt;id&lt;/FONT&gt;) the first observation read from the transaction dataset&amp;nbsp;&lt;SPAN&gt;becomes the basis for an observation in the output data set WANT because there is no observation in the master dataset. (Otherwise, the existing observation in the master dataset for that BY group would be "updated" with the first observation of the transaction dataset.) The update process then continues with the second observation of the transaction dataset: Non-missing values, here: the value of variable &lt;FONT face="courier new,courier"&gt;date2&lt;/FONT&gt;, replace existing values in the same variable (here: the missing value of &lt;FONT face="courier new,courier"&gt;date2&lt;/FONT&gt; from the first observation). Missing values, however, do not overwrite existing values. This is why the missing value of &lt;FONT face="courier new,courier"&gt;date1&lt;/FONT&gt; in the second observation of each BY group leaves the existing non-missing value (that was copied from the first observation) unchanged. After the last observation of a BY group has been processed, the observation created by the update process is written to dataset WANT. So, for each ID, variable &lt;FONT face="courier new,courier"&gt;date1&lt;/FONT&gt; contains the last non-missing &lt;FONT face="courier new,courier"&gt;date1&lt;/FONT&gt; value read from the transaction dataset and, similarly,&amp;nbsp;&lt;FONT face="courier new,courier"&gt;date2&lt;/FONT&gt; the last non-missing &lt;FONT face="courier new,courier"&gt;date2&lt;/FONT&gt; value.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;See&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/lrcon/9.4/n1tgk0uanvisvon1r26lc036k0w7.htm#n1vxpg6f8o73frn15ckfchbfmj6w" target="_blank" rel="noopener"&gt;DATA Step Processing with the UPDATE Statement&lt;/A&gt; for more details and also the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/p18w3br45er2qun1r8sfmm4grjyr.htm#p11l5jqxrqs5n3n1nm8dk2nbyu3n" target="_blank" rel="noopener"&gt;examples&lt;/A&gt; in the documentation of the UPDATE statement.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Aug 2021 21:39:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Base-sas/m-p/764352#M242103</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-08-26T21:39:57Z</dc:date>
    </item>
  </channel>
</rss>

