<?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: creating multiple records based on if condition is true in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/creating-multiple-records-based-on-if-condition-is-true/m-p/809739#M319323</link>
    <description>&lt;P&gt;I'm really confused by this line:&lt;/P&gt;
&lt;PRE&gt;If all of CHADRG, CHBNE, CHBRN, CHLVR, CHLNG, CHLYND, CHMES, CHSKN, CHOTH are 0, output 1 record for FATESTCD=CURRSTAT (FALOC will be missing)."&lt;/PRE&gt;
&lt;P&gt;What is FATESTCD, what is CURRSTAT? Maybe I'm just not understanding?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's my shot at it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines delimiter = ',';
input subject :$6. chadrg chbne chbrn chlvr chlng chlynd chmes chskn choth 3.;
datalines;
101001,0,0,0,1,1,1,0,0,1
101002,0,1,0,1,1,1,0,0,0
101003,0,0,0,0,0,0,0,0,0
;
run;

data want (keep = subject category faloc all_zero);
	set have;
		all_zero = (sum(of chadrg -- choth) = 0);
	array _v [*] chadrg -- choth;
	do i = 1 to dim(_v);
		category = vname(_v[i]);
		if category = vname(_v[i]) then faloc = _v[i];
		if all_zero = 1 then faloc = .;
		output;
	end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 25 Apr 2022 16:52:22 GMT</pubDate>
    <dc:creator>maguiremq</dc:creator>
    <dc:date>2022-04-25T16:52:22Z</dc:date>
    <item>
      <title>creating multiple records based on if condition is true</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-multiple-records-based-on-if-condition-is-true/m-p/809707#M319311</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So this is probably pretty straightforward but trying to figure out the most efficient way. So this is what the spec&amp;nbsp; says I need to create for the variable FALOC&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;"create 1 record per metastasis location, i.e., one record for each CHADRG, CHBNE, CHBRN, CHLVR, CHLNG, CHLYND, CHMES, CHSKN, CHOTH =1.&lt;/P&gt;&lt;P&gt;If all of CHADRG, CHBNE, CHBRN, CHLVR, CHLNG, CHLYND, CHMES, CHSKN, CHOTH are 0, output 1 record for FATESTCD=CURRSTAT (FALOC will be missing)."&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And this is the structure filtered to the relevant columns&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="smackerz_0-1650896920796.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/70839iEFBE2929E0BDB074/image-size/medium?v=v2&amp;amp;px=400" role="button" title="smackerz_0-1650896920796.png" alt="smackerz_0-1650896920796.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;So my question is what is the most efficient way to do this? Is it using PROC TRANSPOSE , a DO Loop or something else?. I need to change the values of 1 for each testcode (CHADRG, CHBNE, CHBRN etc) to a text value so is it better to do this after or during. Any help would be greatly appreciated&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Apr 2022 14:30:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-multiple-records-based-on-if-condition-is-true/m-p/809707#M319311</guid>
      <dc:creator>smackerz</dc:creator>
      <dc:date>2022-04-25T14:30:44Z</dc:date>
    </item>
    <item>
      <title>Re: creating multiple records based on if condition is true</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-multiple-records-based-on-if-condition-is-true/m-p/809726#M319317</link>
      <description>Transpose via do loop.</description>
      <pubDate>Mon, 25 Apr 2022 16:14:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-multiple-records-based-on-if-condition-is-true/m-p/809726#M319317</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-04-25T16:14:56Z</dc:date>
    </item>
    <item>
      <title>Re: creating multiple records based on if condition is true</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-multiple-records-based-on-if-condition-is-true/m-p/809737#M319322</link>
      <description>&lt;P&gt;Here's something to get you started. I assume that FALOC will contain the text of the test code (&lt;SPAN&gt;CHADRG, CHBNE, etc.) if the value = 1. If all of the test codes are 0 then FALOC will be missing. I wasn't clear about the FATESTCD, so I didn't address it.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* mock up some data;
data have;
length subjid 8;
array locs(*) CHADRG CHBNE CHBRN CHLVR CHLNG CHLYND CHMES CHSKN CHOTH;
do subjid = 1 to 10;
   do j = 1 to dim(locs);
      if ranuni(123) &amp;lt; .1 then locs(j) = 1;
      else locs(j) = 0;
   end;
   output;
end;
drop j;
run;


data want;
set have;
length faloc $6;
array locs(*) CHADRG CHBNE CHBRN CHLVR CHLNG CHLYND CHMES CHSKN CHOTH;

do i = 1 to dim(locs);
   if locs(i) = 1 then do;
      faloc = vname(locs(i));
      output;
   end;
end;

if sum(of locs(*)) = 0 then do;
   faloc = '';
   output;
end;

drop i CHADRG CHBNE CHBRN CHLVR CHLNG CHLYND CHMES CHSKN CHOTH;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Apr 2022 16:51:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-multiple-records-based-on-if-condition-is-true/m-p/809737#M319322</guid>
      <dc:creator>average_joe</dc:creator>
      <dc:date>2022-04-25T16:51:46Z</dc:date>
    </item>
    <item>
      <title>Re: creating multiple records based on if condition is true</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-multiple-records-based-on-if-condition-is-true/m-p/809739#M319323</link>
      <description>&lt;P&gt;I'm really confused by this line:&lt;/P&gt;
&lt;PRE&gt;If all of CHADRG, CHBNE, CHBRN, CHLVR, CHLNG, CHLYND, CHMES, CHSKN, CHOTH are 0, output 1 record for FATESTCD=CURRSTAT (FALOC will be missing)."&lt;/PRE&gt;
&lt;P&gt;What is FATESTCD, what is CURRSTAT? Maybe I'm just not understanding?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's my shot at it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines delimiter = ',';
input subject :$6. chadrg chbne chbrn chlvr chlng chlynd chmes chskn choth 3.;
datalines;
101001,0,0,0,1,1,1,0,0,1
101002,0,1,0,1,1,1,0,0,0
101003,0,0,0,0,0,0,0,0,0
;
run;

data want (keep = subject category faloc all_zero);
	set have;
		all_zero = (sum(of chadrg -- choth) = 0);
	array _v [*] chadrg -- choth;
	do i = 1 to dim(_v);
		category = vname(_v[i]);
		if category = vname(_v[i]) then faloc = _v[i];
		if all_zero = 1 then faloc = .;
		output;
	end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 25 Apr 2022 16:52:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-multiple-records-based-on-if-condition-is-true/m-p/809739#M319323</guid>
      <dc:creator>maguiremq</dc:creator>
      <dc:date>2022-04-25T16:52:22Z</dc:date>
    </item>
    <item>
      <title>Re: creating multiple records based on if condition is true</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-multiple-records-based-on-if-condition-is-true/m-p/809769#M319332</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/345100"&gt;@average_joe&lt;/a&gt;&amp;nbsp;small suggestion, maybe test if the all are 0 first, that way you can skip the do loop if it's all 0 to be more efficient?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Changing the do loop to an ELSE would help?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
length faloc $6;
array locs(*) CHADRG CHBNE CHBRN CHLVR CHLNG CHLYND CHMES CHSKN CHOTH;

if sum(of locs(*)) = 0 then do;
   faloc = '';
   output;
end;
else do i = 1 to dim(locs);
   if locs(i) = 1 then do;
      faloc = vname(locs(i));
      output;
   end;
end;



drop i CHADRG CHBNE CHBRN CHLVR CHLNG CHLYND CHMES CHSKN CHOTH;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 25 Apr 2022 19:35:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-multiple-records-based-on-if-condition-is-true/m-p/809769#M319332</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-04-25T19:35:27Z</dc:date>
    </item>
  </channel>
</rss>

