<?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: SET data sets and retain values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SET-data-sets-and-retain-values/m-p/787484#M251631</link>
    <description>&lt;P&gt;You should make sure the datasets are using the same structure before using the SET statement to combine them.&lt;/P&gt;
&lt;P&gt;So you should have VAR values of Z and W and that actual data in VALUE.&lt;/P&gt;
&lt;P&gt;Also Your Z and W datasets only have the ID variable.&lt;/P&gt;
&lt;P&gt;Let's assume the other variables are just constant attributes of the ID value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data t1;
  input ID team group Var $ value;
cards;
1 555 8 X1 15
1 555 8 X2 30
1 555 8 X3 40
1 555 8 X4 10
1 555 8 X5 28
2 444 7 X1 48
2 444 7 X2 52
2 444 7 X3 20
2 444 7 X4 15
2 444 7 X5 31
;

Data t2;
  input ID Z ;
cards;
1 100
2 200
;

Data t3;
  input ID W ;
cards;
1 50
2 80
;

proc sort data=t1(keep=id team group) out=ids nodupkey;
  by id;
run;

data z ;
  merge ids t2;
  by id;
  length var $8 value 8;
  var='Z';
  value=z;
  drop z;
run;

data w ;
  merge ids t3;
  by id;
  length var $8 value 8;
  var='W';
  value=w;
  drop w;
run;

data want;
  set t1 w z;
  by id;
run;

proc print;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results&lt;/P&gt;
&lt;PRE&gt;Obs    ID    team    group    Var    value

  1     1     555      8      X1       15
  2     1     555      8      X2       30
  3     1     555      8      X3       40
  4     1     555      8      X4       10
  5     1     555      8      X5       28
  6     1     555      8      W        50
  7     1     555      8      Z       100
  8     2     444      7      X1       48
  9     2     444      7      X2       52
 10     2     444      7      X3       20
 11     2     444      7      X4       15
 12     2     444      7      X5       31
 13     2     444      7      W        80
 14     2     444      7      Z       200

&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 27 Dec 2021 20:20:27 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-12-27T20:20:27Z</dc:date>
    <item>
      <title>SET data sets and retain values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SET-data-sets-and-retain-values/m-p/787483#M251630</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;What is the way to using data sets t1,t2,t3 in order to get the wanted data set ?&lt;/P&gt;
&lt;P&gt;As you can see the desire action is set of data sets but need also to fill up empty fields by the values above&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data t1;
input ID team group Var $ value;
1 555 8 X1 15
1 555 8 X2 30
1 555 8 X3 40
1 555 8 X4 10
1 555 8 X5 28
2 444 7 X1 48
2 444 7 X2 52
2 444 7 X3 20
2 444 7 X4 15
2 444 7 X5 31
;
Run;

Data t2;
input ID Z ;
cards;
1 100
2 200
;
Run;


Data t3;
input ID W ;
cards;
1 50
2 80
;
Run;

/*Wanted data set*/
/*1 555 8 X1 15*/
/*1 555 8 X2 30*/
/*1 555 8 X3 40*/
/*1 555 8 X4 10*/
/*1 555 8 X5 28*/
/*1 555 8 Z 100*/
/*1 555 8 W 50*/
/*2 444 7 X1 48*/
/*2 444 7 X2 52*/
/*2 444 7 X3 20*/
/*2 444 7 X4 15*/
/*2 444 7 X5 31*/
/*2 444 7 Z 200*/
/*2 444 7 W 801*/&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 27 Dec 2021 20:02:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SET-data-sets-and-retain-values/m-p/787483#M251630</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-12-27T20:02:21Z</dc:date>
    </item>
    <item>
      <title>Re: SET data sets and retain values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SET-data-sets-and-retain-values/m-p/787484#M251631</link>
      <description>&lt;P&gt;You should make sure the datasets are using the same structure before using the SET statement to combine them.&lt;/P&gt;
&lt;P&gt;So you should have VAR values of Z and W and that actual data in VALUE.&lt;/P&gt;
&lt;P&gt;Also Your Z and W datasets only have the ID variable.&lt;/P&gt;
&lt;P&gt;Let's assume the other variables are just constant attributes of the ID value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data t1;
  input ID team group Var $ value;
cards;
1 555 8 X1 15
1 555 8 X2 30
1 555 8 X3 40
1 555 8 X4 10
1 555 8 X5 28
2 444 7 X1 48
2 444 7 X2 52
2 444 7 X3 20
2 444 7 X4 15
2 444 7 X5 31
;

Data t2;
  input ID Z ;
cards;
1 100
2 200
;

Data t3;
  input ID W ;
cards;
1 50
2 80
;

proc sort data=t1(keep=id team group) out=ids nodupkey;
  by id;
run;

data z ;
  merge ids t2;
  by id;
  length var $8 value 8;
  var='Z';
  value=z;
  drop z;
run;

data w ;
  merge ids t3;
  by id;
  length var $8 value 8;
  var='W';
  value=w;
  drop w;
run;

data want;
  set t1 w z;
  by id;
run;

proc print;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results&lt;/P&gt;
&lt;PRE&gt;Obs    ID    team    group    Var    value

  1     1     555      8      X1       15
  2     1     555      8      X2       30
  3     1     555      8      X3       40
  4     1     555      8      X4       10
  5     1     555      8      X5       28
  6     1     555      8      W        50
  7     1     555      8      Z       100
  8     2     444      7      X1       48
  9     2     444      7      X2       52
 10     2     444      7      X3       20
 11     2     444      7      X4       15
 12     2     444      7      X5       31
 13     2     444      7      W        80
 14     2     444      7      Z       200

&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Dec 2021 20:20:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SET-data-sets-and-retain-values/m-p/787484#M251631</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-12-27T20:20:27Z</dc:date>
    </item>
    <item>
      <title>Re: SET data sets and retain values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SET-data-sets-and-retain-values/m-p/787485#M251632</link>
      <description>&lt;P&gt;There will be several ways.&amp;nbsp; Here's a way that uses a single DATA step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set t1;
   by id;
   output;
   if last.id;
   group_no + 1;
   set t2 point=group_no;
    var = "Z";
    value = z;
    output;
   set t3 point=group_no;
   var = "W";
   value = w;
   output;
   drop group_no w z;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If ID really does take on sequential values 1, 2, 3, etc., the program could be simplified.&amp;nbsp; Get rid of GROUP_NO and use ID as the POINT= variable.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Dec 2021 20:43:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SET-data-sets-and-retain-values/m-p/787485#M251632</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2021-12-27T20:43:33Z</dc:date>
    </item>
    <item>
      <title>Re: SET data sets and retain values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SET-data-sets-and-retain-values/m-p/787501#M251640</link>
      <description>&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;The ID in real data is not a sequence number.&lt;/P&gt;
&lt;P&gt;May you please tell the terminology that you used in your code.&lt;/P&gt;
&lt;P&gt;I would like to understand your code better .&lt;/P&gt;
&lt;P&gt;Why do you use "output" statement 3 times?&lt;/P&gt;
&lt;P&gt;Why do you use last statement one time?&lt;/P&gt;
&lt;P&gt;Why do you use&amp;nbsp;point statement two times?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data t1;
  input ID team group Var $ value;
cards;
111 555 8 X1 15
111 555 8 X2 30
223 444 7 X3 20
223 444 7 X4 15
111 555 8 X3 40
111 555 8 X4 10
111 555 8 X5 28
223 444 7 X1 48
223 444 7 X2 52
223 444 7 X5 31
;
Run;

Data t2;
  input ID Z ;
cards;
111 100
223 200
;
Run;


Data t3;
  input ID W ;
cards;
111 50
223 80
;
Run;

proc sort data=t1;by ID;Run;
proc sort data=t2;by ID;Run;
proc sort data=t3;by ID;Run;

data want;
set t1;
by id;
output;
if last.id;
group_no + 1;
set t2 point=group_no;
var = "Z";
value = z;
output;
set t3 point=group_no;
var = "W";
value = w;
output;
drop group_no w z;
run;



 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 Dec 2021 06:09:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SET-data-sets-and-retain-values/m-p/787501#M251640</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-12-28T06:09:08Z</dc:date>
    </item>
    <item>
      <title>Re: SET data sets and retain values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SET-data-sets-and-retain-values/m-p/787539#M251652</link>
      <description>&lt;P&gt;There are three OUTPUT statements, because there are three situations where I want to output an observation:&amp;nbsp; after reading an observation from t1, after reading an observation from t2, and after reading an observation from t3.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is only one BY statement, so there is only one set of first. and last. variables available.&amp;nbsp; No need to refer to any other such variables, because they don't exist.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Using point= twice is overkill.&amp;nbsp; In retrospect, none of them are needed.&amp;nbsp; The program could be shortened as follows:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set t1;
by id;
output;
if last.id;
set t2;
var = "Z";
value = z;
output;
set t3;
var = "W";
value = w;
output;
drop w z;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 Dec 2021 19:10:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SET-data-sets-and-retain-values/m-p/787539#M251652</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2021-12-28T19:10:21Z</dc:date>
    </item>
  </channel>
</rss>

