<?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: Equating variable values for all observations within a BY group in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Equating-variable-values-for-all-observations-within-a-BY-group/m-p/72277#M15581</link>
    <description>Thanks so much - I've tried this approach and it almost works, but I'm not sure whether I'm not sorting properly or whether something else happens when I merge.  I've been using the code below, and whenever there are &amp;gt;2 observations for the same subject ID, I end up with missing values in the middle observation(s) within the subject ID BY group for the variable "x" (e.g., the first and last observations will have the proper value for x, but everything in between is still missing).  Do you happen to know why this might be occurring?&lt;BR /&gt;
Thanks again for your help - code below.&lt;BR /&gt;
NG&lt;BR /&gt;
&lt;BR /&gt;
data x_merge;&lt;BR /&gt;
	set x (keep=id x);&lt;BR /&gt;
	if x = .  then delete;&lt;BR /&gt;
	run;&lt;BR /&gt;
proc sort data=x;&lt;BR /&gt;
by id;&lt;BR /&gt;
run;&lt;BR /&gt;
proc sort data=x_merge;&lt;BR /&gt;
by id;&lt;BR /&gt;
run;&lt;BR /&gt;
data x_update;&lt;BR /&gt;
	merge x  x_merge;&lt;BR /&gt;
	by id;&lt;BR /&gt;
	run;</description>
    <pubDate>Mon, 21 Sep 2009 02:39:32 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2009-09-21T02:39:32Z</dc:date>
    <item>
      <title>Equating variable values for all observations within a BY group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Equating-variable-values-for-all-observations-within-a-BY-group/m-p/72275#M15579</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
I have a data set with multiple observations per subject, and for one particular variable there is a value for the last observation for each subject, but for other observations within the subject the value is missing - e.g.,&lt;BR /&gt;
&lt;BR /&gt;
id1 obs1  .&lt;BR /&gt;
id1 obs2  .&lt;BR /&gt;
id1 obs3  .&lt;BR /&gt;
id1 obs4  x&lt;BR /&gt;
&lt;BR /&gt;
How can I set the value of the variable to "x" within each subject's entire BY group, so that each observation for the same subject has the value "x"?&lt;BR /&gt;
&lt;BR /&gt;
Thanks so much for any insight - I haven't been able to figure out a way to program this using FIRST.variables or LAST.variables.&lt;BR /&gt;
&lt;BR /&gt;
NG</description>
      <pubDate>Sun, 20 Sep 2009 04:13:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Equating-variable-values-for-all-observations-within-a-BY-group/m-p/72275#M15579</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-09-20T04:13:10Z</dc:date>
    </item>
    <item>
      <title>Re: Equating variable values for all observations within a BY group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Equating-variable-values-for-all-observations-within-a-BY-group/m-p/72276#M15580</link>
      <description>For a DATA step approach, create a separate file having only your BY variable(s) and the variable "x".  Sort both files on the BY list.  Then MERGE back in the newly created file with your primary file, using the BY statement variable list.&lt;BR /&gt;
&lt;BR /&gt;
You will find several SAS-hosted DOC and supplemental technical/conference reference documents - suggest using the Google advanced search argument below to find matches with explanations and examples for both DATA step and PROC SQL approaches:&lt;BR /&gt;
&lt;BR /&gt;
data step merge site:sas.com&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Sun, 20 Sep 2009 07:47:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Equating-variable-values-for-all-observations-within-a-BY-group/m-p/72276#M15580</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-09-20T07:47:58Z</dc:date>
    </item>
    <item>
      <title>Re: Equating variable values for all observations within a BY group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Equating-variable-values-for-all-observations-within-a-BY-group/m-p/72277#M15581</link>
      <description>Thanks so much - I've tried this approach and it almost works, but I'm not sure whether I'm not sorting properly or whether something else happens when I merge.  I've been using the code below, and whenever there are &amp;gt;2 observations for the same subject ID, I end up with missing values in the middle observation(s) within the subject ID BY group for the variable "x" (e.g., the first and last observations will have the proper value for x, but everything in between is still missing).  Do you happen to know why this might be occurring?&lt;BR /&gt;
Thanks again for your help - code below.&lt;BR /&gt;
NG&lt;BR /&gt;
&lt;BR /&gt;
data x_merge;&lt;BR /&gt;
	set x (keep=id x);&lt;BR /&gt;
	if x = .  then delete;&lt;BR /&gt;
	run;&lt;BR /&gt;
proc sort data=x;&lt;BR /&gt;
by id;&lt;BR /&gt;
run;&lt;BR /&gt;
proc sort data=x_merge;&lt;BR /&gt;
by id;&lt;BR /&gt;
run;&lt;BR /&gt;
data x_update;&lt;BR /&gt;
	merge x  x_merge;&lt;BR /&gt;
	by id;&lt;BR /&gt;
	run;</description>
      <pubDate>Mon, 21 Sep 2009 02:39:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Equating-variable-values-for-all-observations-within-a-BY-group/m-p/72277#M15581</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-09-21T02:39:32Z</dc:date>
    </item>
    <item>
      <title>Re: Equating variable values for all observations within a BY group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Equating-variable-values-for-all-observations-within-a-BY-group/m-p/72278#M15582</link>
      <description>The following should work:&lt;BR /&gt;
&lt;BR /&gt;
/* assuming data x is sorted by id, x */&lt;BR /&gt;
data x_merge;&lt;BR /&gt;
  set x(keep=id x);&lt;BR /&gt;
  by id x;&lt;BR /&gt;
  if last.id then output;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data x_update;&lt;BR /&gt;
  merge x(drop=x) x_merge;&lt;BR /&gt;
  by id;&lt;BR /&gt;
run; &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
In your example:&lt;BR /&gt;
- is x numeric or character?&lt;BR /&gt;
- could it be that not only the last obs per id has a value and you end up with a many to many merge?</description>
      <pubDate>Mon, 21 Sep 2009 08:57:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Equating-variable-values-for-all-observations-within-a-BY-group/m-p/72278#M15582</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2009-09-21T08:57:55Z</dc:date>
    </item>
    <item>
      <title>Re: Equating variable values for all observations within a BY group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Equating-variable-values-for-all-observations-within-a-BY-group/m-p/72279#M15583</link>
      <description>this works - thanks so much for your help!&lt;BR /&gt;
&lt;BR /&gt;
NG</description>
      <pubDate>Mon, 21 Sep 2009 13:38:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Equating-variable-values-for-all-observations-within-a-BY-group/m-p/72279#M15583</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-09-21T13:38:53Z</dc:date>
    </item>
    <item>
      <title>Re: Equating variable values for all observations within a BY group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Equating-variable-values-for-all-observations-within-a-BY-group/m-p/72280#M15584</link>
      <description>You can even do Patrick's suggestion in one go:&lt;BR /&gt;
&lt;BR /&gt;
data x_update;&lt;BR /&gt;
merge x(drop=x) x(keep=id x where=(x ne .));&lt;BR /&gt;
by id;&lt;BR /&gt;
run;</description>
      <pubDate>Mon, 21 Sep 2009 22:44:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Equating-variable-values-for-all-observations-within-a-BY-group/m-p/72280#M15584</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2009-09-21T22:44:40Z</dc:date>
    </item>
  </channel>
</rss>

