<?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: Assign Existing Variable Values to All Other Observations Within Groups in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Assign-Existing-Variable-Values-to-All-Other-Observations-Within/m-p/744085#M233056</link>
    <description>The below is submitted via my smartphone which is not offered a code submission option on this website. &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;data Have;&lt;BR /&gt;input Trial Treatment Replication VariableX;&lt;BR /&gt;datalines;&lt;BR /&gt;1 1  1 a&lt;BR /&gt;1 1  2 b&lt;BR /&gt;1 2  1 c&lt;BR /&gt;1 2  2 d&lt;BR /&gt;1 3  1 e&lt;BR /&gt;1 3  2 f&lt;BR /&gt;2 1  1 g&lt;BR /&gt;2 1  2 h&lt;BR /&gt;2 2  1 i&lt;BR /&gt;2 2  2 j&lt;BR /&gt;2 3  1 k&lt;BR /&gt;2 3  2 l&lt;BR /&gt;;&lt;BR /&gt;&lt;BR /&gt;data want (drop=_:);&lt;BR /&gt;  set have;&lt;BR /&gt;  by  trial treatment;&lt;BR /&gt;  retain _get . ;&lt;BR /&gt;  array tmp{10} _temporary_;&lt;BR /&gt;  if first.trial then call missing (_get, of tmp{*});&lt;BR /&gt;  else if first.treatment then _get=1;&lt;BR /&gt;  if _get=1 then variablex=tmp[replication];&lt;BR /&gt;  else tmp[replication]=variablex;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;The above accommodates replications 1 through 10.</description>
    <pubDate>Thu, 27 May 2021 03:40:49 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2021-05-27T03:40:49Z</dc:date>
    <item>
      <title>Assign Existing Variable Values to All Other Observations Within Groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-Existing-Variable-Values-to-All-Other-Observations-Within/m-p/744072#M233050</link>
      <description>&lt;P&gt;This may be a basic question but it has been difficult to find a solution on my own.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have data that is organized into multiple groups, including trial, treatment, and replication. I wish to create a new variable for the entire data set using values from an observation presently assigned to a given treatment within a trial and replication (for later use as a covariate). This new variable should be assigned to all other observations with a given trial and replication.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is what I current have:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data Have;&lt;/P&gt;&lt;P&gt;Input Trial Treatment Replication VariableX;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;1 1&amp;nbsp; 1 a&lt;/P&gt;&lt;P&gt;1 1&amp;nbsp; 2 b&lt;/P&gt;&lt;P&gt;1 2&amp;nbsp; 1 c&lt;/P&gt;&lt;P&gt;1 2&amp;nbsp; 2 d&lt;/P&gt;&lt;P&gt;1 3&amp;nbsp; 1 e&lt;/P&gt;&lt;P&gt;1 3&amp;nbsp; 2 f&lt;/P&gt;&lt;P&gt;2 1&amp;nbsp; 1 g&lt;/P&gt;&lt;P&gt;2 1&amp;nbsp; 2 h&lt;/P&gt;&lt;P&gt;2 2&amp;nbsp; 1 i&lt;/P&gt;&lt;P&gt;2 2&amp;nbsp; 2 j&lt;/P&gt;&lt;P&gt;2 3&amp;nbsp; 1 k&lt;/P&gt;&lt;P&gt;2 3&amp;nbsp; 2 l&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is what I want:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data Want;&lt;/P&gt;&lt;P&gt;Input Trial Treatment Replication VariableX VariableY;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;1 1&amp;nbsp; 1 a a&lt;/P&gt;&lt;P&gt;1 1&amp;nbsp; 2 b b&lt;/P&gt;&lt;P&gt;1 2&amp;nbsp; 1 c a&lt;/P&gt;&lt;P&gt;1 2&amp;nbsp; 2 d b&lt;/P&gt;&lt;P&gt;1 3&amp;nbsp; 1 e a&lt;/P&gt;&lt;P&gt;1 3&amp;nbsp; 2 f b&lt;/P&gt;&lt;P&gt;2 1&amp;nbsp; 1 g g&lt;/P&gt;&lt;P&gt;2 1&amp;nbsp; 2 h h&lt;/P&gt;&lt;P&gt;2 2&amp;nbsp; 1 i g&lt;/P&gt;&lt;P&gt;2 2&amp;nbsp; 2 j h&lt;/P&gt;&lt;P&gt;2 3&amp;nbsp; 1 k g&lt;/P&gt;&lt;P&gt;2 3&amp;nbsp; 2 l h&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be greatly appreciated.&lt;/P&gt;</description>
      <pubDate>Thu, 27 May 2021 01:07:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-Existing-Variable-Values-to-All-Other-Observations-Within/m-p/744072#M233050</guid>
      <dc:creator>gentd</dc:creator>
      <dc:date>2021-05-27T01:07:28Z</dc:date>
    </item>
    <item>
      <title>Re: Assign Existing Variable Values to All Other Observations Within Groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-Existing-Variable-Values-to-All-Other-Observations-Within/m-p/744076#M233054</link>
      <description>&lt;P&gt;The following code "saves" the observed value of VariableX from the first treatment for each combination of Test and Replication,&amp;nbsp;and then pastes it to the original table as VariableY:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select a.Trial, a.Treatment,a.Replication,a.VariableX, b.VariableX as VariableY
from (select Trial, Treatment,Replication,VariableX 
	  from have) as a                                   

		inner join 

	(select Trial, Replication, VariableX      /*Select the value of VariableX of the first observed(lowest value) treatment, for each combination of Trial and Replication*/
	 from have
	 group by Trial, Replication
	 having Treatment=min(Treatment)) as b on  (a.Trial=b.Trial and a.Replication=b.Replication)    
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 27 May 2021 02:05:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-Existing-Variable-Values-to-All-Other-Observations-Within/m-p/744076#M233054</guid>
      <dc:creator>Angel_Larrion</dc:creator>
      <dc:date>2021-05-27T02:05:09Z</dc:date>
    </item>
    <item>
      <title>Re: Assign Existing Variable Values to All Other Observations Within Groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-Existing-Variable-Values-to-All-Other-Observations-Within/m-p/744085#M233056</link>
      <description>The below is submitted via my smartphone which is not offered a code submission option on this website. &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;data Have;&lt;BR /&gt;input Trial Treatment Replication VariableX;&lt;BR /&gt;datalines;&lt;BR /&gt;1 1  1 a&lt;BR /&gt;1 1  2 b&lt;BR /&gt;1 2  1 c&lt;BR /&gt;1 2  2 d&lt;BR /&gt;1 3  1 e&lt;BR /&gt;1 3  2 f&lt;BR /&gt;2 1  1 g&lt;BR /&gt;2 1  2 h&lt;BR /&gt;2 2  1 i&lt;BR /&gt;2 2  2 j&lt;BR /&gt;2 3  1 k&lt;BR /&gt;2 3  2 l&lt;BR /&gt;;&lt;BR /&gt;&lt;BR /&gt;data want (drop=_:);&lt;BR /&gt;  set have;&lt;BR /&gt;  by  trial treatment;&lt;BR /&gt;  retain _get . ;&lt;BR /&gt;  array tmp{10} _temporary_;&lt;BR /&gt;  if first.trial then call missing (_get, of tmp{*});&lt;BR /&gt;  else if first.treatment then _get=1;&lt;BR /&gt;  if _get=1 then variablex=tmp[replication];&lt;BR /&gt;  else tmp[replication]=variablex;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;The above accommodates replications 1 through 10.</description>
      <pubDate>Thu, 27 May 2021 03:40:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-Existing-Variable-Values-to-All-Other-Observations-Within/m-p/744085#M233056</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-05-27T03:40:49Z</dc:date>
    </item>
    <item>
      <title>Re: Assign Existing Variable Values to All Other Observations Within Groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-Existing-Variable-Values-to-All-Other-Observations-Within/m-p/744091#M233057</link>
      <description>&lt;P&gt;I would do it like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Have;
Input Trial Treatment Replication VariableX $;
datalines;
1 1  1 a
1 1  2 b
1 2  1 c
1 2  2 d
1 3  1 e
1 3  2 f
2 1  1 g
2 1  2 h
2 2  1 i
2 2  2 j
2 3  1 k
2 3  2 l
;run;

proc sort data=have;
  by trial replication treatment;
run;

data want;
  set have;
  by trial replication;
  if first.replication then VariableY=VariableX;
  retain VariableY;
run;

proc sort data=want;
  by trial treatment replication;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 27 May 2021 06:24:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-Existing-Variable-Values-to-All-Other-Observations-Within/m-p/744091#M233057</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2021-05-27T06:24:30Z</dc:date>
    </item>
    <item>
      <title>Re: Assign Existing Variable Values to All Other Observations Within Groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-Existing-Variable-Values-to-All-Other-Observations-Within/m-p/744125#M233072</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Have;
Input Trial Treatment Replication VariableX $;
datalines;
1 1  1 a
1 1  2 b
1 2  1 c
1 2  2 d
1 3  1 e
1 3  2 f
2 1  1 g
2 1  2 h
2 2  1 i
2 2  2 j
2 3  1 k
2 3  2 l
;

proc sql;
create table want as
select a.*,b.VariableX as VariableY
 from have as a left join (select * from have where Treatment=1) as b 
  on a.Trial=b.Trial and a.Replication=b.Replication
   order by 1,2,3
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 27 May 2021 12:33:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-Existing-Variable-Values-to-All-Other-Observations-Within/m-p/744125#M233072</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-05-27T12:33:42Z</dc:date>
    </item>
    <item>
      <title>Re: Assign Existing Variable Values to All Other Observations Within Groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-Existing-Variable-Values-to-All-Other-Observations-Within/m-p/744264#M233152</link>
      <description>Thank you Angel_Larrion! My actual data set has numeric values for 'Treatment' but I was above to modify your code to select the values for the 'Non-Treated' treatment of interest.</description>
      <pubDate>Thu, 27 May 2021 18:25:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-Existing-Variable-Values-to-All-Other-Observations-Within/m-p/744264#M233152</guid>
      <dc:creator>gentd</dc:creator>
      <dc:date>2021-05-27T18:25:56Z</dc:date>
    </item>
  </channel>
</rss>

