<?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: adding observations according to variable values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/adding-observations-according-to-variable-values/m-p/960371#M374567</link>
    <description>&lt;P&gt;You are not explaining your problem very clearly.&lt;/P&gt;
&lt;P&gt;Let's see if we can guess what you are asking to do.&lt;/P&gt;
&lt;P&gt;I suspect that you are trying to automate some part of the process of generating metadata about clinical trial data from your use of dataset names like ADAE and ADSL&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you seem to have a dataset named HAVE which has incomplete metadata about the variables in the datasets used (generated for?) your clinical trial.&amp;nbsp;&lt;/P&gt;
&lt;LI-SPOILER&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	infile cards dsd truncover ;
	input dataset :$32. variable :$32. label :$256. coregroup $;
cards;
ADAE,USUBJID,Subject ID,
ADAE,:CORE1,,
ADAE,:CORE2,,
ADAE,TRT,Treatment,
ADMH,USUBJID,Subject ID,
ADMH,MHTERM,Medical History Term,
ADMH,TRT,Treatment Group,
ADSL,USUBJID,Subject ID,
ADSL,RAND,Rand flag,1,
ADSL,ETHNEW,New Ethnicity,2,
ADSL,SITEID,Site ID,1,
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1740627620590.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/104996i6720205548FBCD0E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1740627620590.png" alt="Tom_0-1740627620590.png" /&gt;&lt;/span&gt;&lt;/LI-SPOILER&gt;
&lt;P&gt;The source of this incompleteness is the use of special values like ':CORE1' and 'CORE2' as PLACEHOLDERS for an actual set of variable names that should be inserted into the metadata table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you should be able to do some simple joins to get what you want.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select  dataset,variable,label
  from have
  where not (variable eqt ':CORE')
union
select a.dataset,b.variable,b.label
  from have a
  inner join have b
  on a.variable eqt ':CORE'
    and b.dataset='ADSL' and b.coregroup=substr(a.variable,6)
order by dataset,variable
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_1-1740628029249.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/104997i15E6415E98AEF80C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_1-1740628029249.png" alt="Tom_1-1740628029249.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 27 Feb 2025 03:47:15 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2025-02-27T03:47:15Z</dc:date>
    <item>
      <title>adding observations according to variable values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/adding-observations-according-to-variable-values/m-p/960240#M374531</link>
      <description>&lt;P&gt;hi, I have a situation where ADSL variables are selectively added to a list. In this example CORE1 should be replaced by a list of variables present in ADSL that have a coregroup of 1. CORE2 should be replaced by a list of variables in ADSL with coregroup of 2 and so on. I would like to automate this addition of variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HAVE:&lt;/P&gt;
&lt;P&gt;dataset variable label coregroup&lt;/P&gt;
&lt;P&gt;ADAE&amp;nbsp;&amp;nbsp; USUBJID&amp;nbsp; Subject ID&lt;/P&gt;
&lt;P&gt;ADAE &lt;STRONG&gt;:CORE1&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;ADAE&lt;STRONG&gt; :CORE2&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;ADAE&amp;nbsp; TRT&amp;nbsp; Treatment&lt;/P&gt;
&lt;P&gt;ADMH &amp;nbsp; USUBJID&amp;nbsp; Subject ID&lt;/P&gt;
&lt;P&gt;ADMH&amp;nbsp; MHTERM&amp;nbsp; Medical History Term&lt;/P&gt;
&lt;P&gt;ADMH&amp;nbsp; TRT&amp;nbsp; Treatment Group&lt;/P&gt;
&lt;P&gt;ADSL&amp;nbsp; USUBJID&amp;nbsp; Subject ID&lt;/P&gt;
&lt;P&gt;ADSL RAND&amp;nbsp; Rand flag&amp;nbsp; &lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;ADSL ETHNEW&amp;nbsp; New Ethnicity&lt;STRONG&gt;&amp;nbsp; 2&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;ADSL&amp;nbsp; SITEID&amp;nbsp; Site ID&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;WANT:&lt;/P&gt;
&lt;P&gt;dataset variable label coregroup&lt;/P&gt;
&lt;P&gt;ADAE&amp;nbsp;&amp;nbsp; USUBJID&amp;nbsp; Subject ID&lt;/P&gt;
&lt;P&gt;ADAE RAND&amp;nbsp; Rand flag&amp;nbsp; &lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;ADAE ETHNEW&amp;nbsp; New Ethnicity&lt;STRONG&gt;&amp;nbsp; 2&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;ADAE&amp;nbsp; TRT&amp;nbsp; Treatment&lt;/P&gt;
&lt;P&gt;ADMH &amp;nbsp; USUBJID&amp;nbsp; Subject ID&lt;/P&gt;
&lt;P&gt;ADMH&amp;nbsp; MHTERM&amp;nbsp; Medical History Term&lt;/P&gt;
&lt;P&gt;ADMH&amp;nbsp; TRT&amp;nbsp; Treatment Group&lt;/P&gt;
&lt;P&gt;ADSL&amp;nbsp; USUBJID&amp;nbsp; Subject ID&lt;/P&gt;
&lt;P&gt;ADSL RAND&amp;nbsp; Rand flag&amp;nbsp; &lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;ADSL ETHNEW&amp;nbsp; New Ethnicity&lt;STRONG&gt;&amp;nbsp; 2&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;ADSL&amp;nbsp; SITEID&amp;nbsp; Site ID&lt;/P&gt;</description>
      <pubDate>Wed, 26 Feb 2025 12:25:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/adding-observations-according-to-variable-values/m-p/960240#M374531</guid>
      <dc:creator>kalbo</dc:creator>
      <dc:date>2025-02-26T12:25:48Z</dc:date>
    </item>
    <item>
      <title>Re: adding observations according to variable values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/adding-observations-according-to-variable-values/m-p/960241#M374532</link>
      <description>&lt;P&gt;Please post data in usable form, making it easier to understand the problem and giving us something to work with.&lt;/P&gt;
&lt;P&gt;The output statement can be used to create additional obs.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Feb 2025 12:31:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/adding-observations-according-to-variable-values/m-p/960241#M374532</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2025-02-26T12:31:33Z</dc:date>
    </item>
    <item>
      <title>Re: adding observations according to variable values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/adding-observations-according-to-variable-values/m-p/960243#M374533</link>
      <description>&lt;P&gt;In addition to the request from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15475"&gt;@andreas_lds&lt;/a&gt;&amp;nbsp;, please tell us if this is the entire data set, or if this is just a small part of a much larger data set. (If it is much larger, please tell us how many rows). Are there different subjects or different IDs in this larger data set? Would the code need to be smart enough to make different replacements for different subjects/different IDs?&lt;/P&gt;</description>
      <pubDate>Wed, 26 Feb 2025 12:59:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/adding-observations-according-to-variable-values/m-p/960243#M374533</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-02-26T12:59:28Z</dc:date>
    </item>
    <item>
      <title>Re: adding observations according to variable values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/adding-observations-according-to-variable-values/m-p/960246#M374535</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	infile cards dsd;
	input dataset $ variable : $10. label : $20. coregroup $;
	cards;
ADAE,USUBJID,Subject ID,
ADAE,:CORE1,,
ADAE,:CORE2,,
ADAE,TRT,Treatment,
ADMH,USUBJID,Subject ID,
ADMH,MHTERM,Medical History Term,
ADMH,TRT,Treatment Group,
ADSL,USUBJID,Subject ID,
ADSL,RAND,Rand flag,1,
ADSL,ETHNEW,New Ethnicity,2,
ADSL,SITEID,Site ID,1,
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 26 Feb 2025 13:33:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/adding-observations-according-to-variable-values/m-p/960246#M374535</guid>
      <dc:creator>kalbo</dc:creator>
      <dc:date>2025-02-26T13:33:59Z</dc:date>
    </item>
    <item>
      <title>Re: adding observations according to variable values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/adding-observations-according-to-variable-values/m-p/960247#M374536</link>
      <description>&lt;P&gt;For example to process CORE1, we need to find all records in ADSL with coregroup=1. Then add these 2 records in to replace CORE1.&lt;/P&gt;
&lt;P&gt;ADAE RAND&amp;nbsp; Rand flag&amp;nbsp; &lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;ADAE&amp;nbsp; SITEID&amp;nbsp; Site ID&lt;STRONG&gt; 1&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then move to CORE2 and add in the following records to replace CORE2:&lt;/P&gt;
&lt;P&gt;ADAE ETHNEW&amp;nbsp; New Ethnicity&amp;nbsp; &lt;STRONG&gt;2&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The ADSL records can be added to any data set in the list which will contain all data sets. The list isnt so big.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;WANT:&lt;/P&gt;
&lt;P&gt;dataset variable label coregroup&lt;/P&gt;
&lt;P&gt;ADAE&amp;nbsp;&amp;nbsp; USUBJID&amp;nbsp; Subject ID&lt;/P&gt;
&lt;P&gt;ADAE RAND&amp;nbsp; Rand flag&amp;nbsp; &lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;ADAE&amp;nbsp; SITEID&amp;nbsp; Site ID&lt;STRONG&gt; 1&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;ADAE ETHNEW&amp;nbsp; New Ethnicity&lt;STRONG&gt;&amp;nbsp; 2&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;ADAE&amp;nbsp; TRT&amp;nbsp; Treatment&lt;/P&gt;
&lt;P&gt;ADMH &amp;nbsp; USUBJID&amp;nbsp; Subject ID&lt;/P&gt;
&lt;P&gt;ADMH&amp;nbsp; MHTERM&amp;nbsp; Medical History Term&lt;/P&gt;
&lt;P&gt;ADMH&amp;nbsp; TRT&amp;nbsp; Treatment Group&lt;/P&gt;
&lt;P&gt;ADSL&amp;nbsp; USUBJID&amp;nbsp; Subject ID&lt;/P&gt;
&lt;P&gt;ADSL RAND&amp;nbsp; Rand flag&amp;nbsp; &lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;ADSL ETHNEW&amp;nbsp; New Ethnicity&lt;STRONG&gt;&amp;nbsp; 2&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;ADSL&amp;nbsp; SITEID&amp;nbsp; Site ID &lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Feb 2025 13:40:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/adding-observations-according-to-variable-values/m-p/960247#M374536</guid>
      <dc:creator>kalbo</dc:creator>
      <dc:date>2025-02-26T13:40:04Z</dc:date>
    </item>
    <item>
      <title>Re: adding observations according to variable values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/adding-observations-according-to-variable-values/m-p/960248#M374537</link>
      <description>&lt;P&gt;The example I gave is a part of a data set (which is the metadata of adam data sets) which is about 1000 rows. I would need to replace any CORE value with observations from the ADSL. Can be up to 4 core groupings. So whenever CORE1, 2, 3 etc appears it should also work for those.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Feb 2025 13:42:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/adding-observations-according-to-variable-values/m-p/960248#M374537</guid>
      <dc:creator>kalbo</dc:creator>
      <dc:date>2025-02-26T13:42:31Z</dc:date>
    </item>
    <item>
      <title>Re: adding observations according to variable values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/adding-observations-according-to-variable-values/m-p/960249#M374538</link>
      <description>&lt;P&gt;I asked "&lt;SPAN&gt;Are there different subjects or different IDs in this larger data set? Would the code need to be smart enough to make different replacements for different subjects/different IDs?" I don't see an answer.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Feb 2025 13:51:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/adding-observations-according-to-variable-values/m-p/960249#M374538</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-02-26T13:51:49Z</dc:date>
    </item>
    <item>
      <title>Re: adding observations according to variable values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/adding-observations-according-to-variable-values/m-p/960250#M374539</link>
      <description>&lt;P&gt;hi, yes there would be other data sets listed. The id is the coregroup of 1,2,3 or 4 (for ADSL) which corresponds to CORE1, 2, 4, 5 for all other data sets.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Feb 2025 13:54:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/adding-observations-according-to-variable-values/m-p/960250#M374539</guid>
      <dc:creator>kalbo</dc:creator>
      <dc:date>2025-02-26T13:54:28Z</dc:date>
    </item>
    <item>
      <title>Re: adding observations according to variable values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/adding-observations-according-to-variable-values/m-p/960252#M374540</link>
      <description>&lt;P&gt;yes it should&amp;nbsp; be smart enough to handle that.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Feb 2025 13:59:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/adding-observations-according-to-variable-values/m-p/960252#M374540</guid>
      <dc:creator>kalbo</dc:creator>
      <dc:date>2025-02-26T13:59:52Z</dc:date>
    </item>
    <item>
      <title>Re: adding observations according to variable values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/adding-observations-according-to-variable-values/m-p/960254#M374541</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/160861"&gt;@kalbo&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;hi, yes there would be other data sets listed. The id is the coregroup of 1,2,3 or 4 (for ADSL) which corresponds to CORE1, 2, 4, 5 for all other data sets.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Not sure I understand this. It would help to see other data sets.&amp;nbsp;Could you please provide sample data which covers at least two data sets?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Lots of words have been written, I have to scroll up and down to get a complete picture. Can you rewrite the question to address all of these concerns in one post?&lt;/P&gt;</description>
      <pubDate>Wed, 26 Feb 2025 14:32:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/adding-observations-according-to-variable-values/m-p/960254#M374541</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-02-26T14:32:19Z</dc:date>
    </item>
    <item>
      <title>Re: adding observations according to variable values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/adding-observations-according-to-variable-values/m-p/960351#M374563</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/160861"&gt;@kalbo&lt;/a&gt;&amp;nbsp;Your descriptions are somewhat confusing. May be that's because of formulations like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;gt;&lt;SPAN&gt;CORE1 should be replaced by a list of variables&lt;/SPAN&gt;&lt;BR /&gt;That's not a list of variables. You want to replace records with specific values for variables &lt;EM&gt;dataset&lt;/EM&gt; and &lt;EM&gt;variable&lt;/EM&gt; with values from some other records in the same table. What increases the confusion are the variable names "variable" and "dataset".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;gt;&lt;SPAN&gt;The ADSL records can be added to any data set in the list&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;What's confusing here: In the SAS world the term "data set" normally means "table" and not row/observation/record.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Based on your WANT data I believe what you're after is something like below:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile cards dsd truncover;
  input dataset $ variable : $10. label : $20. coregroup $;
  cards;
ADAE,USUBJID,Subject_ID,
ADAE,:CORE1,,
ADAE,:CORE2,,
ADAE,TRT,Treatment,
ADMH,USUBJID,Subject_ID,
ADMH,MHTERM,Medical_History_Term,
ADMH,TRT,Treatment_Group,
ADSL,USUBJID,Subject_ID,
ADSL,RAND,Rand_flag,1,
ADSL,ETHNEW,New_Ethnicity,2,
ADSL,SITEID,Site_ID,1,
;

data want;
   input dataset $ variable : $10. label : $20. coregroup $;
   datalines;
ADAE USUBJID Subject_ID .
ADAE RAND Rand_flag 1
ADAE SITEID Site_ID 1
ADAE ETHNEW New_Ethnicity 2
ADAE TRT Treatment .
ADMH USUBJID Subject_ID .
ADMH MHTERM Medical_History_Term .
ADMH TRT Treatment_Group .
ADSL USUBJID Subject_ID .
ADSL RAND Rand_flag 1
ADSL ETHNEW New_Ethnicity 2
ADSL SITEID Site_ID 1
;
run;

data want_derived;
  if _n_=1 then
    do;
      dcl hash h1(dataset:'have(where=(dataset="ADSL" and not missing(coregroup))', multidata:'y');
      h1.defineKey('coregroup');
      h1.defineData('variable','label','coregroup');
      h1.defineDone();
    end;
  set have;
  if dataset='ADAE' and find(variable,'core','i')&amp;gt;0 then
    do;
      do while(h1.do_over(key:strip(scan(variable,-1,,'kd'))) eq 0);
        output;
      end;
    end;
  else
    output;
run;

proc compare data=want compare=want_derived;
run;
proc print data=want;run;
proc print data=want_derived;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 26 Feb 2025 23:44:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/adding-observations-according-to-variable-values/m-p/960351#M374563</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2025-02-26T23:44:53Z</dc:date>
    </item>
    <item>
      <title>Re: adding observations according to variable values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/adding-observations-according-to-variable-values/m-p/960371#M374567</link>
      <description>&lt;P&gt;You are not explaining your problem very clearly.&lt;/P&gt;
&lt;P&gt;Let's see if we can guess what you are asking to do.&lt;/P&gt;
&lt;P&gt;I suspect that you are trying to automate some part of the process of generating metadata about clinical trial data from your use of dataset names like ADAE and ADSL&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you seem to have a dataset named HAVE which has incomplete metadata about the variables in the datasets used (generated for?) your clinical trial.&amp;nbsp;&lt;/P&gt;
&lt;LI-SPOILER&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	infile cards dsd truncover ;
	input dataset :$32. variable :$32. label :$256. coregroup $;
cards;
ADAE,USUBJID,Subject ID,
ADAE,:CORE1,,
ADAE,:CORE2,,
ADAE,TRT,Treatment,
ADMH,USUBJID,Subject ID,
ADMH,MHTERM,Medical History Term,
ADMH,TRT,Treatment Group,
ADSL,USUBJID,Subject ID,
ADSL,RAND,Rand flag,1,
ADSL,ETHNEW,New Ethnicity,2,
ADSL,SITEID,Site ID,1,
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1740627620590.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/104996i6720205548FBCD0E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1740627620590.png" alt="Tom_0-1740627620590.png" /&gt;&lt;/span&gt;&lt;/LI-SPOILER&gt;
&lt;P&gt;The source of this incompleteness is the use of special values like ':CORE1' and 'CORE2' as PLACEHOLDERS for an actual set of variable names that should be inserted into the metadata table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you should be able to do some simple joins to get what you want.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select  dataset,variable,label
  from have
  where not (variable eqt ':CORE')
union
select a.dataset,b.variable,b.label
  from have a
  inner join have b
  on a.variable eqt ':CORE'
    and b.dataset='ADSL' and b.coregroup=substr(a.variable,6)
order by dataset,variable
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_1-1740628029249.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/104997i15E6415E98AEF80C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_1-1740628029249.png" alt="Tom_1-1740628029249.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Feb 2025 03:47:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/adding-observations-according-to-variable-values/m-p/960371#M374567</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-02-27T03:47:15Z</dc:date>
    </item>
  </channel>
</rss>

