<?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: Populating value based on condition for all rows in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Populating-value-based-on-condition-for-all-rows/m-p/834664#M329956</link>
    <description>&lt;P&gt;From the example data posted I think that your requirement&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="578"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="578"&gt;Set B1IND to the value of A1IND where ABLFL equals "Y" within each USUBJID and PARAMCD.&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;may perhaps be better stated is "If any ABLFL = 'Y' for a combination of USUBJID and PARAMCD then set B1IND to the value of A1IND from the record where ABLFL='Y'. Is this an accurate description or paraphrase of the requirement?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"Each" in the first statement would for many things mean that the record, not the group, is treated as such. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One additional question: do you ever have multiple values of ABLFL other than missing for a USUBJID and PARAMCD? If so do they have different values of A1IND? That would mean that you need to extend the rule.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have not checked that condition you might run code on your data set like this to get counts of combinations that actually occur in your data.&lt;/P&gt;
&lt;PRE&gt;Proc freq data=have;
   where not missing(ABLFL );
   tables USUBJID * PARAMCD *ABLFL *A1IND / list;
run;&lt;/PRE&gt;
&lt;P&gt;Additional comment: Your requirement shows use of the variable USUBJID variable. Your example data does not include that variable. When we have to guess that one variable is supposed be used in a different role/position/name then results can be off. So it is a good idea to make variable names match consistently.&lt;/P&gt;</description>
    <pubDate>Thu, 22 Sep 2022 14:30:26 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2022-09-22T14:30:26Z</dc:date>
    <item>
      <title>Populating value based on condition for all rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Populating-value-based-on-condition-for-all-rows/m-p/834625#M329949</link>
      <description>&lt;P&gt;Hello.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a specification for B1IND&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="578"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="578"&gt;Set B1IND to the value of A1IND where ABLFL equals "Y" within each USUBJID and PARAMCD.&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input SUBJID $ :$40. PARAMCD :$14. PARAMN: $2. A1IND :$40. ABLFL :$2. B1IND :$40.;
infile datalines dlm = '|';
datalines;
1001|HGB|1|Within range| |High 		
1001|HGB|1|High|Y|High
1001|HGB|1|Within range| |High		
1001|HGB|1|Low|	|High	
1001|HGB|1|Low|	|High	
1001|HGB|1|Within range| |High		
1001|HCT|2|No criteria defined for parameter| |No criteria defined for parameter	
1001|HCT|2|No criteria defined for parameter|Y|No criteria defined for parameter
1001|HCT|2|No criteria defined for parameter| |No criteria defined for parameter
1001|HCT|2|No criteria defined for parameter| |No criteria defined for parameter
1001|HCT|2|No criteria defined for parameter| |No criteria defined for parameter
1001|HCT|2|No criteria defined for parameter| |No criteria defined for parameter
1001|WBCH|4|High| |Within range
1001|WBCH|4|Within range|Y |Within range
1001|WBCH|4|Within range|  |Within range	
1001|WBCH|4|Within range|  |Within range	
1001|WBCH|4|Within range|  |Within range	
1001|WBCH|4|Within range|  |Within range	
;	&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Ideally I would want to create a column for B1IND and have the baseline value (where ABLFL='Y') displayed for all rows per paramcd/paramn. I tried using the RETAIN/OUTPUT statement but it wasn't working as intended. Any suggestions?&lt;/P&gt;</description>
      <pubDate>Thu, 22 Sep 2022 10:09:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Populating-value-based-on-condition-for-all-rows/m-p/834625#M329949</guid>
      <dc:creator>smackerz1988</dc:creator>
      <dc:date>2022-09-22T10:09:11Z</dc:date>
    </item>
    <item>
      <title>Re: Populating value based on condition for all rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Populating-value-based-on-condition-for-all-rows/m-p/834629#M329951</link>
      <description>&lt;P&gt;Can you add B1IND to your data set so we know what the expected output looks like?&lt;/P&gt;</description>
      <pubDate>Thu, 22 Sep 2022 09:30:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Populating-value-based-on-condition-for-all-rows/m-p/834629#M329951</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2022-09-22T09:30:40Z</dc:date>
    </item>
    <item>
      <title>Re: Populating value based on condition for all rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Populating-value-based-on-condition-for-all-rows/m-p/834630#M329952</link>
      <description>&lt;P&gt;No problem. I've updated the sample data EDIT: Apologies there was an error for the desired outcome for the last paramcd which I've fixed&lt;/P&gt;</description>
      <pubDate>Thu, 22 Sep 2022 10:10:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Populating-value-based-on-condition-for-all-rows/m-p/834630#M329952</guid>
      <dc:creator>smackerz1988</dc:creator>
      <dc:date>2022-09-22T10:10:48Z</dc:date>
    </item>
    <item>
      <title>Re: Populating value based on condition for all rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Populating-value-based-on-condition-for-all-rows/m-p/834664#M329956</link>
      <description>&lt;P&gt;From the example data posted I think that your requirement&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="578"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="578"&gt;Set B1IND to the value of A1IND where ABLFL equals "Y" within each USUBJID and PARAMCD.&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;may perhaps be better stated is "If any ABLFL = 'Y' for a combination of USUBJID and PARAMCD then set B1IND to the value of A1IND from the record where ABLFL='Y'. Is this an accurate description or paraphrase of the requirement?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"Each" in the first statement would for many things mean that the record, not the group, is treated as such. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One additional question: do you ever have multiple values of ABLFL other than missing for a USUBJID and PARAMCD? If so do they have different values of A1IND? That would mean that you need to extend the rule.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have not checked that condition you might run code on your data set like this to get counts of combinations that actually occur in your data.&lt;/P&gt;
&lt;PRE&gt;Proc freq data=have;
   where not missing(ABLFL );
   tables USUBJID * PARAMCD *ABLFL *A1IND / list;
run;&lt;/PRE&gt;
&lt;P&gt;Additional comment: Your requirement shows use of the variable USUBJID variable. Your example data does not include that variable. When we have to guess that one variable is supposed be used in a different role/position/name then results can be off. So it is a good idea to make variable names match consistently.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Sep 2022 14:30:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Populating-value-based-on-condition-for-all-rows/m-p/834664#M329956</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-09-22T14:30:26Z</dc:date>
    </item>
    <item>
      <title>Re: Populating value based on condition for all rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Populating-value-based-on-condition-for-all-rows/m-p/834668#M329957</link>
      <description>&lt;P&gt;Thanks appreciated. yes that was just a typo with the USUBJID and no just one record per parameter with a value of 'Y' for ABLFL but that is good thinking. Here is the code I settled on and works fine.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
    create table b1ind as
        select distinct usubjid
                       ,paramcd
			           ,a1ind 
        from lbchg2
        where ABLFL ='Y'
    order by 1;

  /* Merge b1ind back onto the original record*/
     create table lbchg3 as
     select a.*,
          b.a1ind as b1ind          
   from lbchg2 a left join b1ind b on a.usubjid=b.usubjid   and
                                      a.paramcd=b.paramcd;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Sep 2022 15:00:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Populating-value-based-on-condition-for-all-rows/m-p/834668#M329957</guid>
      <dc:creator>smackerz1988</dc:creator>
      <dc:date>2022-09-22T15:00:29Z</dc:date>
    </item>
  </channel>
</rss>

