<?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: Inserting a column into a data set in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Inserting-a-column-into-a-data-set/m-p/624734#M184072</link>
    <description>&lt;P&gt;Post actual data. Like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
  do id=1 to 10;
    ratio=2.5;
    output;
  end;
run;

data b;
  id=0;
  do time=1 to 24 ;
    id=id+1;
    conc = round(ranuni(0),0.01);
    output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now use that data:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set b;
  if _n_=1 then set a(keep=ratio);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;Obs    id    time    conc    ratio

  1     1      1     0.31     2.5
  2     2      2     0.74     2.5
  3     3      3     0.52     2.5
  4     4      4     0.84     2.5
  5     5      5     0.09     2.5
  6     6      6     0.33     2.5
  7     7      7     0.11     2.5
  8     8      8     0.87     2.5
  9     9      9     0.61     2.5
 10    10     10     0.43     2.5
 11    11     11     0.92     2.5
 12    12     12     0.79     2.5
 13    13     13     0.91     2.5
 14    14     14     0.98     2.5
 15    15     15     0.41     2.5
 16    16     16     0.50     2.5
 17    17     17     0.21     2.5
 18    18     18     0.55     2.5
 19    19     19     0.31     2.5
 20    20     20     0.38     2.5
 21    21     21     0.43     2.5
 22    22     22     0.49     2.5
 23    23     23     0.71     2.5
 24    24     24     0.96     2.5&lt;/PRE&gt;
&lt;P&gt;The only way that running that step would result in any missing values for RATIO would be if the variable already existed in dataset B.&amp;nbsp; In that case you could just drop it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set b(drop=ratio);
  if _n_=1 then set a(keep=ratio);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It is still not clear why you made the A dataset have 10 observations instead of one.&lt;/P&gt;</description>
    <pubDate>Fri, 14 Feb 2020 04:35:52 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2020-02-14T04:35:52Z</dc:date>
    <item>
      <title>Inserting a column into a data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Inserting-a-column-into-a-data-set/m-p/624701#M184063</link>
      <description>&lt;P&gt;If I have a data set A:&lt;/P&gt;&lt;P&gt;ID &amp;nbsp; Ratio&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp;&amp;nbsp; 5&lt;/P&gt;&lt;P&gt;. &amp;nbsp; &amp;nbsp; &amp;nbsp; 5&lt;/P&gt;&lt;P&gt;10 &amp;nbsp; &amp;nbsp; 5&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data set B:&lt;/P&gt;&lt;P&gt;ID &amp;nbsp; Time&amp;nbsp; conc&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp;&amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;. &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.5&lt;/P&gt;&lt;P&gt;24 &amp;nbsp;&amp;nbsp; 24 &amp;nbsp; &amp;nbsp; 0.01&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The (.) means that there are several values for A that end at 10 while for B they end at 24.&amp;nbsp; The question is how can I introduce the constant ratio value 5 into data B from data A for all the rows in data set B?&lt;/P&gt;</description>
      <pubDate>Fri, 14 Feb 2020 00:25:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Inserting-a-column-into-a-data-set/m-p/624701#M184063</guid>
      <dc:creator>jacksonan123</dc:creator>
      <dc:date>2020-02-14T00:25:40Z</dc:date>
    </item>
    <item>
      <title>Re: Inserting a column into a data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Inserting-a-column-into-a-data-set/m-p/624707#M184064</link>
      <description>&lt;P&gt;I don't follow.&amp;nbsp; You want a constant?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set B;
  ratio=5;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You want the constant that is in dataset A?&amp;nbsp; Just take the first copy of it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set B;
  if _n_=1 then set A(keep=ratio);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want something else you need to explain the rules in more detail.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Feb 2020 01:14:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Inserting-a-column-into-a-data-set/m-p/624707#M184064</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-02-14T01:14:46Z</dc:date>
    </item>
    <item>
      <title>Re: Inserting a column into a data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Inserting-a-column-into-a-data-set/m-p/624732#M184071</link>
      <description>I tried your solution but it put in the column for ratio, but it was all&lt;BR /&gt;missing values. Let me try to explain again with my data set want.&lt;BR /&gt;&lt;BR /&gt;Data a;&lt;BR /&gt;&lt;BR /&gt;ID Ratio&lt;BR /&gt;&lt;BR /&gt;1 2.5&lt;BR /&gt;&lt;BR /&gt;. 2.5&lt;BR /&gt;&lt;BR /&gt;10 2.5&lt;BR /&gt;&lt;BR /&gt;Data B;&lt;BR /&gt;&lt;BR /&gt;ID Time Conc&lt;BR /&gt;&lt;BR /&gt;1 0 0&lt;BR /&gt;&lt;BR /&gt;. 1 0.5&lt;BR /&gt;&lt;BR /&gt;24 24 0.25&lt;BR /&gt;&lt;BR /&gt;Data Want:&lt;BR /&gt;&lt;BR /&gt;ID Time Conc Ratio&lt;BR /&gt;&lt;BR /&gt;1 0 0 2.5&lt;BR /&gt;&lt;BR /&gt;. 1 0.5 2.5&lt;BR /&gt;&lt;BR /&gt;24 24 0.25 2.5&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 14 Feb 2020 03:55:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Inserting-a-column-into-a-data-set/m-p/624732#M184071</guid>
      <dc:creator>jacksonan123</dc:creator>
      <dc:date>2020-02-14T03:55:00Z</dc:date>
    </item>
    <item>
      <title>Re: Inserting a column into a data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Inserting-a-column-into-a-data-set/m-p/624734#M184072</link>
      <description>&lt;P&gt;Post actual data. Like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
  do id=1 to 10;
    ratio=2.5;
    output;
  end;
run;

data b;
  id=0;
  do time=1 to 24 ;
    id=id+1;
    conc = round(ranuni(0),0.01);
    output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now use that data:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set b;
  if _n_=1 then set a(keep=ratio);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;Obs    id    time    conc    ratio

  1     1      1     0.31     2.5
  2     2      2     0.74     2.5
  3     3      3     0.52     2.5
  4     4      4     0.84     2.5
  5     5      5     0.09     2.5
  6     6      6     0.33     2.5
  7     7      7     0.11     2.5
  8     8      8     0.87     2.5
  9     9      9     0.61     2.5
 10    10     10     0.43     2.5
 11    11     11     0.92     2.5
 12    12     12     0.79     2.5
 13    13     13     0.91     2.5
 14    14     14     0.98     2.5
 15    15     15     0.41     2.5
 16    16     16     0.50     2.5
 17    17     17     0.21     2.5
 18    18     18     0.55     2.5
 19    19     19     0.31     2.5
 20    20     20     0.38     2.5
 21    21     21     0.43     2.5
 22    22     22     0.49     2.5
 23    23     23     0.71     2.5
 24    24     24     0.96     2.5&lt;/PRE&gt;
&lt;P&gt;The only way that running that step would result in any missing values for RATIO would be if the variable already existed in dataset B.&amp;nbsp; In that case you could just drop it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set b(drop=ratio);
  if _n_=1 then set a(keep=ratio);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It is still not clear why you made the A dataset have 10 observations instead of one.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Feb 2020 04:35:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Inserting-a-column-into-a-data-set/m-p/624734#M184072</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-02-14T04:35:52Z</dc:date>
    </item>
    <item>
      <title>Re: Inserting a column into a data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Inserting-a-column-into-a-data-set/m-p/624772#M184085</link>
      <description>When data A was generated it had some other values that were needed other&lt;BR /&gt;than ratio.&lt;BR /&gt;&lt;BR /&gt;Your answer was a solution and in the future when possible I will submit&lt;BR /&gt;data as you suggested.&lt;BR /&gt;&lt;BR /&gt;I had always thought that when one set a data set meant that one data set&lt;BR /&gt;was placed on top of the other and merge was the way to combine but I stand&lt;BR /&gt;corrected by you code.&lt;BR /&gt;</description>
      <pubDate>Fri, 14 Feb 2020 10:08:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Inserting-a-column-into-a-data-set/m-p/624772#M184085</guid>
      <dc:creator>jacksonan123</dc:creator>
      <dc:date>2020-02-14T10:08:00Z</dc:date>
    </item>
    <item>
      <title>Re: Inserting a column into a data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Inserting-a-column-into-a-data-set/m-p/624846#M184108</link>
      <description>&lt;P&gt;SET (and MERGE) are executable statements.&amp;nbsp; Each time it execute it reads another observation from the dataset(s).&lt;/P&gt;
&lt;P&gt;That is why you can do code like this to process all of the records for a group in iteration of the data step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do until(last.id);
  set have;
  by id;
 ....
end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 14 Feb 2020 14:46:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Inserting-a-column-into-a-data-set/m-p/624846#M184108</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-02-14T14:46:20Z</dc:date>
    </item>
    <item>
      <title>Re: Inserting a column into a data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Inserting-a-column-into-a-data-set/m-p/624873#M184125</link>
      <description>Thanks for the explanation.&lt;BR /&gt;</description>
      <pubDate>Fri, 14 Feb 2020 15:54:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Inserting-a-column-into-a-data-set/m-p/624873#M184125</guid>
      <dc:creator>jacksonan123</dc:creator>
      <dc:date>2020-02-14T15:54:00Z</dc:date>
    </item>
  </channel>
</rss>

