<?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: Normalizing SAS data to make sure a particular variable or column as the latest entry per the da in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Normalizing-SAS-data-to-make-sure-a-particular-variable-or/m-p/777209#M247233</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/376137"&gt;@kmin87&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;thanks for the solution. That worked!!! I do have a follow up question if you dont mind. I am now merging this data set to another data set. So this new data set has entries with more columns. One of the column im checking for in this data set is with another column in the data set you just showed me. So lets say the want data set has a column titled correct_a and i have an original data set that the corresponding column a. I want to make sure the column a has the correct values according to correct_a. Some are equal and some may be different. WOuld this code work?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;data new;&lt;BR /&gt;  merge original(in=a)&lt;BR /&gt;want(in=b);&lt;BR /&gt;by id rank;&lt;BR /&gt;if a=1;&lt;BR /&gt;if a ne correct_a then a=correct_a;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I doubt it depending on what you expect. If you have a variable named A in your data when you use the IN=A dataset option it means that unexpected things can happen as shown here:&lt;/P&gt;
&lt;PRE&gt;64   data junk;
65      set sashelp.class (in=age);
66   run;

WARNING: The variable age exists on an input data set and is also set by an I/O statement option.
          The variable will not be included on any output data set and unexpected results can
         occur.
NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: The data set WORK.JUNK has 19 observations and 4 variables.

&lt;/PRE&gt;
&lt;P&gt;Sashelp.class started with 5 variables.&lt;/P&gt;
&lt;P&gt;You likely should use a different variable for your IN variable. Typically I use In&amp;lt;datasetname&amp;gt;, such as InOrginal so the code documents what the use of that variable is doing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I understand what you are attempting I would try something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;data new;&lt;BR /&gt;  merge original(in=InOriginal)&lt;BR /&gt;        want(in=b)&lt;BR /&gt;  ;&lt;BR /&gt;  by id rank;&lt;BR /&gt;  if InOriginal=1;&lt;BR /&gt;  a = coalesce(correct_a,a);&lt;BR /&gt;&lt;BR /&gt;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The above assumes a and correct_a are numeric values. If the variables are character then use CoalesceC instead. The Coalesce function returns the first non-missing value in the list compared left to right.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that the following is going to attempt to execute when Correct_a is missing as missing value is not equal to any actual value. So you might end up removing values of A when there isn't any actual observation from the Want data set with matching Id Rank.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;if a ne correct_a then a=correct_a;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp; &lt;/P&gt;</description>
    <pubDate>Fri, 29 Oct 2021 09:40:20 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2021-10-29T09:40:20Z</dc:date>
    <item>
      <title>Normalizing SAS data to make sure a particular variable or column as the latest entry per the date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Normalizing-SAS-data-to-make-sure-a-particular-variable-or/m-p/777050#M247172</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a new data set where I want to normalize. For example I want to get the most updated Code identifier for John Smith of that particular rank. So I want to just maintain data where Smith, John Code AC and rank junior or 2nd row in a new data set.&lt;/P&gt;&lt;P&gt;I want to go through each entries, and make sure the right rank is with the right code per the most current date.&lt;/P&gt;&lt;P&gt;How do i write a sas program to do this?&lt;/P&gt;</description>
      <pubDate>Thu, 28 Oct 2021 17:04:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Normalizing-SAS-data-to-make-sure-a-particular-variable-or/m-p/777050#M247172</guid>
      <dc:creator>kmin87</dc:creator>
      <dc:date>2021-10-28T17:04:37Z</dc:date>
    </item>
    <item>
      <title>Re: Normalizing SAS data to make sure a particular variable or column as the latest entry per the da</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Normalizing-SAS-data-to-make-sure-a-particular-variable-or/m-p/777063#M247176</link>
      <description>&lt;P&gt;Many of us will not download Excel files as they are security threat. Instead of file attachments, include your data in your reply as SAS data step code (&lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;instructions&lt;/A&gt;).&lt;/P&gt;</description>
      <pubDate>Thu, 28 Oct 2021 17:12:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Normalizing-SAS-data-to-make-sure-a-particular-variable-or/m-p/777063#M247176</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-10-28T17:12:18Z</dc:date>
    </item>
    <item>
      <title>Re: Normalizing SAS data to make sure a particular variable or column as the latest entry per the da</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Normalizing-SAS-data-to-make-sure-a-particular-variable-or/m-p/777066#M247177</link>
      <description>&lt;P&gt;Oh okay, here is the data set&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Name	ID	Code	Rank	Date
Smith, John	1	AB	Junior	20170801
Smith, John	1	AC	Junior	20170901
Smith, John	1	AD	Senior	20180101
Smith, Peter	2	TT	Manager	20170801
Smith, Peter	2	TP	Manager	20171001
Ask, Teom	3	AB	Junior	20170801
Powell, H	4	TT	Manager	20170801
Powell, H	4	TP	Senior	20190801
​&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Oct 2021 17:14:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Normalizing-SAS-data-to-make-sure-a-particular-variable-or/m-p/777066#M247177</guid>
      <dc:creator>kmin87</dc:creator>
      <dc:date>2021-10-28T17:14:28Z</dc:date>
    </item>
    <item>
      <title>Re: Normalizing SAS data to make sure a particular variable or column as the latest entry per the da</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Normalizing-SAS-data-to-make-sure-a-particular-variable-or/m-p/777070#M247179</link>
      <description>&lt;P&gt;Assuming your&amp;nbsp;data is properly sorted by ID and RANK and DATE&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* UNTESTED CODE */
data want;
    set have;
    by id rank;
    if last.rank;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want tested code, you need to supply data according to the instructions given.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Oct 2021 17:26:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Normalizing-SAS-data-to-make-sure-a-particular-variable-or/m-p/777070#M247179</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-10-28T17:26:49Z</dc:date>
    </item>
    <item>
      <title>Re: Normalizing SAS data to make sure a particular variable or column as the latest entry per the da</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Normalizing-SAS-data-to-make-sure-a-particular-variable-or/m-p/777095#M247185</link>
      <description>&lt;P&gt;thanks for the solution. That worked!!! I do have a follow up question if you dont mind. I am now merging this data set to another data set. So this new data set has entries with more columns. One of the column im checking for in this data set is with another column in the data set you just showed me. So lets say the want data set has a column titled correct_a and i have an original data set that the corresponding column a. I want to make sure the column a has the correct values according to correct_a. Some are equal and some may be different. WOuld this code work?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data new;&lt;BR /&gt;  merge original(in=a)&lt;BR /&gt;want(in=b);&lt;BR /&gt;by id rank;&lt;BR /&gt;if a=1;&lt;BR /&gt;if a ne correct_a then a=correct_a;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Oct 2021 18:23:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Normalizing-SAS-data-to-make-sure-a-particular-variable-or/m-p/777095#M247185</guid>
      <dc:creator>kmin87</dc:creator>
      <dc:date>2021-10-28T18:23:36Z</dc:date>
    </item>
    <item>
      <title>Re: Normalizing SAS data to make sure a particular variable or column as the latest entry per the da</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Normalizing-SAS-data-to-make-sure-a-particular-variable-or/m-p/777209#M247233</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/376137"&gt;@kmin87&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;thanks for the solution. That worked!!! I do have a follow up question if you dont mind. I am now merging this data set to another data set. So this new data set has entries with more columns. One of the column im checking for in this data set is with another column in the data set you just showed me. So lets say the want data set has a column titled correct_a and i have an original data set that the corresponding column a. I want to make sure the column a has the correct values according to correct_a. Some are equal and some may be different. WOuld this code work?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;data new;&lt;BR /&gt;  merge original(in=a)&lt;BR /&gt;want(in=b);&lt;BR /&gt;by id rank;&lt;BR /&gt;if a=1;&lt;BR /&gt;if a ne correct_a then a=correct_a;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I doubt it depending on what you expect. If you have a variable named A in your data when you use the IN=A dataset option it means that unexpected things can happen as shown here:&lt;/P&gt;
&lt;PRE&gt;64   data junk;
65      set sashelp.class (in=age);
66   run;

WARNING: The variable age exists on an input data set and is also set by an I/O statement option.
          The variable will not be included on any output data set and unexpected results can
         occur.
NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: The data set WORK.JUNK has 19 observations and 4 variables.

&lt;/PRE&gt;
&lt;P&gt;Sashelp.class started with 5 variables.&lt;/P&gt;
&lt;P&gt;You likely should use a different variable for your IN variable. Typically I use In&amp;lt;datasetname&amp;gt;, such as InOrginal so the code documents what the use of that variable is doing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I understand what you are attempting I would try something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;data new;&lt;BR /&gt;  merge original(in=InOriginal)&lt;BR /&gt;        want(in=b)&lt;BR /&gt;  ;&lt;BR /&gt;  by id rank;&lt;BR /&gt;  if InOriginal=1;&lt;BR /&gt;  a = coalesce(correct_a,a);&lt;BR /&gt;&lt;BR /&gt;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The above assumes a and correct_a are numeric values. If the variables are character then use CoalesceC instead. The Coalesce function returns the first non-missing value in the list compared left to right.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that the following is going to attempt to execute when Correct_a is missing as missing value is not equal to any actual value. So you might end up removing values of A when there isn't any actual observation from the Want data set with matching Id Rank.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;if a ne correct_a then a=correct_a;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp; &lt;/P&gt;</description>
      <pubDate>Fri, 29 Oct 2021 09:40:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Normalizing-SAS-data-to-make-sure-a-particular-variable-or/m-p/777209#M247233</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-10-29T09:40:20Z</dc:date>
    </item>
  </channel>
</rss>

