<?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: Using IF-THEN/ELSE statements to create a flag indicating presence or absence of a disease in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-IF-THEN-ELSE-statements-to-create-a-flag-indicating/m-p/416091#M102155</link>
    <description>&lt;P&gt;You need to get rid of the RUN statement in the middle of your data step.&amp;nbsp; It looks like there is an extra end statement.&amp;nbsp; This would be a lot easier to look at with reasonable indentation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 24 Nov 2017 21:39:03 GMT</pubDate>
    <dc:creator>WarrenKuhfeld</dc:creator>
    <dc:date>2017-11-24T21:39:03Z</dc:date>
    <item>
      <title>Using IF-THEN/ELSE statements to create a flag indicating presence or absence of a disease</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-IF-THEN-ELSE-statements-to-create-a-flag-indicating/m-p/416079#M102150</link>
      <description>&lt;P&gt;Create a new variable called&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;&lt;EM&gt;disease&lt;/EM&gt;&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;and make it equal to 1 if a person has complaints of heartburns, sickness,&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;and&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;spasm, but no temperature or tiredness.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If the person does not have this exact symptom breakdown, make&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;&lt;EM&gt;disease&lt;/EM&gt;&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;equal to 0.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Lastly, use PROC FREQ to determine what number and proportion of individuals in the dataset has the disease of interest.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I do not know how to do this. Any hints or help? I am studying for an exam and need to understand this program.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have to use if and then statements.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is what I have so far.... it is not working.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; proc format; 
value symptom_no	1= "heartburns" 
					2= "Sickness"
					3= "Spasm"
					4= "Temperature"
					5= "Tiredness"; 
		
proc sort data=Project3 out= longsort; 
 	by id_no; 
run; 
data new; 
	set longsort; 
	by id_no; 
	Keep id_no sympt1 - sympt5 disease; 
	retain sympt1 - sympt5 disease; 
	disease=0;
	array New_a (1:5) $20 sympt1 - sympt5; 
	If first.id_no then
	do; 
	Do i = 1 to 5; 
		new_a (i) = .; 
		end; 

	new_a (symptom_no) = symptom; 
	if last.id_no then output; 
		run; 
	array New_b (1) disease; 
	If sympt1 ='heartburns' and sympt2='sickness' and sympt3='spasm' then disease='1';
	else disease='0'; 
		end; 
	end; 

		run; 
	proc print data= new; 
	run; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 Nov 2017 20:30:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-IF-THEN-ELSE-statements-to-create-a-flag-indicating/m-p/416079#M102150</guid>
      <dc:creator>jessica_join</dc:creator>
      <dc:date>2017-11-24T20:30:17Z</dc:date>
    </item>
    <item>
      <title>Re: Using IF-THEN/ELSE statements to create a flag indicating presence or absence of a disease</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-IF-THEN-ELSE-statements-to-create-a-flag-indicating/m-p/416091#M102155</link>
      <description>&lt;P&gt;You need to get rid of the RUN statement in the middle of your data step.&amp;nbsp; It looks like there is an extra end statement.&amp;nbsp; This would be a lot easier to look at with reasonable indentation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Nov 2017 21:39:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-IF-THEN-ELSE-statements-to-create-a-flag-indicating/m-p/416091#M102155</guid>
      <dc:creator>WarrenKuhfeld</dc:creator>
      <dc:date>2017-11-24T21:39:03Z</dc:date>
    </item>
    <item>
      <title>Re: Using IF-THEN/ELSE statements to create a flag indicating presence or absence of a disease</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-IF-THEN-ELSE-statements-to-create-a-flag-indicating/m-p/416095#M102157</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Its a little unclear on the structure of your original data, so I've made an assumption that it simply has a single numeric symptom column to start with (with values 1 to 5) and multiple rows per ID depending on number of symptoms. In order to make the logic more transparent i.e. move away from arrays (for now). I reckon it might look something like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data new; 
  set longsort; 
  by id_no; 
	
  retain heartburn sickness spasm temperature tiredness;
  
  if (first.id_no) then
  do;
    heartburn   =0;
    sickness    =0;
    spasm       =0;
    temperature =0;
    tiredness   =0;
  end;

  if symptom=1 then heartburn  =1; 
  if symptom=2 then sickness   =1; 
  if symptom=3 then spasm      =1;
  if symptom=4 then temperature=1; 
  if symptom=5 then tiredness  =1;

  if (heartburn)    and 
     (sickness)     and 
     (spasm)        and 
     ^(temperature) and 
     ^(tiredness)   then disease =1; else
                         disease =0;
                         
   if (last.id_no);
 run;
 
 proc freq data=new;
   table disease;
 run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 Nov 2017 22:24:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-IF-THEN-ELSE-statements-to-create-a-flag-indicating/m-p/416095#M102157</guid>
      <dc:creator>Enio</dc:creator>
      <dc:date>2017-11-24T22:24:56Z</dc:date>
    </item>
    <item>
      <title>Re: Using IF-THEN/ELSE statements to create a flag indicating presence or absence of a disease</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-IF-THEN-ELSE-statements-to-create-a-flag-indicating/m-p/416096#M102158</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/72792"&gt;@Enio&lt;/a&gt;&amp;nbsp;This is a homework assignment, she has to use arrays.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Nov 2017 22:26:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-IF-THEN-ELSE-statements-to-create-a-flag-indicating/m-p/416096#M102158</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-11-24T22:26:19Z</dc:date>
    </item>
    <item>
      <title>Re: Using IF-THEN/ELSE statements to create a flag indicating presence or absence of a disease</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-IF-THEN-ELSE-statements-to-create-a-flag-indicating/m-p/416100#M102159</link>
      <description>&lt;P&gt;You're right, and that's cool. Hopefully the code above helps to explain what the arrays are trying to do. With arrays it would probably look something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data new(drop=symptom i); 
  set longsort; 
  by id_no; 
	
  retain sympt1 - sympt5;
  
  array new_a (1:5) sympt1 - sympt5;
  
  do i = 1 to 5 ;
  
    if (first.id_no) then
    do;
      new_a(i) =0;
    end;

    if symptom=i then new_a(i)  =1; 

  end;
  
  if (sympt1)    and 
     (sympt2)    and 
     (sympt3)    and 
     ^(sympt4)   and 
     ^(sympt5)   then disease =1; else
                      disease =0;
                         
   if (last.id_no);
 run;
 
 proc freq data=new;
   table disease;
 run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 Nov 2017 22:52:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-IF-THEN-ELSE-statements-to-create-a-flag-indicating/m-p/416100#M102159</guid>
      <dc:creator>Enio</dc:creator>
      <dc:date>2017-11-24T22:52:53Z</dc:date>
    </item>
    <item>
      <title>Re: Using IF-THEN/ELSE statements to create a flag indicating presence or absence of a disease</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-IF-THEN-ELSE-statements-to-create-a-flag-indicating/m-p/416102#M102160</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/72792"&gt;@Enio&lt;/a&gt;&amp;nbsp;some&amp;nbsp;small changes - noted by Warren earlier I think. That END after the line below should be moved up, or the do loop could be simplified.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;    if symptom=i then new_a(i)  =1; 

end; *This needs to be moved up;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The i reference isn't correct in this case, because the diagnosis are being moved to specific points. Those are defined by symbol_num (sp?) variable.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Though... symptoms in the previous question were text, but they appear to be character here so I'm slightly confused myself.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A previous version of this question is linked to below for your information.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/Base-SAS-Programming/SAS-new-variable/m-p/415698" target="_blank"&gt;https://communities.sas.com/t5/Base-SAS-Programming/SAS-new-variable/m-p/415698&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/Base-SAS-Programming/Array-First-id-retain-last-id/m-p/415699" target="_blank"&gt;https://communities.sas.com/t5/Base-SAS-Programming/Array-First-id-retain-last-id/m-p/415699&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Nov 2017 23:04:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-IF-THEN-ELSE-statements-to-create-a-flag-indicating/m-p/416102#M102160</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-11-24T23:04:29Z</dc:date>
    </item>
    <item>
      <title>Re: Using IF-THEN/ELSE statements to create a flag indicating presence or absence of a disease</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-IF-THEN-ELSE-statements-to-create-a-flag-indicating/m-p/416103#M102161</link>
      <description>&lt;P&gt;Also note that it seems like a big misconception among many programmers is that you need if/then/else to assign a binary value to a variable.&amp;nbsp; NOT TRUE!&amp;nbsp; This works just fine and requires only a single statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;variable = boolean-expression&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A boolean expression (and/or/eq/ne/gt/ge/lt/le etc) resolves to zero or one.&amp;nbsp; You can assign that value to a variable.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Nov 2017 23:08:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-IF-THEN-ELSE-statements-to-create-a-flag-indicating/m-p/416103#M102161</guid>
      <dc:creator>WarrenKuhfeld</dc:creator>
      <dc:date>2017-11-24T23:08:21Z</dc:date>
    </item>
    <item>
      <title>Re: Using IF-THEN/ELSE statements to create a flag indicating presence or absence of a disease</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-IF-THEN-ELSE-statements-to-create-a-flag-indicating/m-p/416123#M102163</link>
      <description>&lt;P&gt;This is my preferred way of visual coding style:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data new; 
set longsort; 
by id_no; 
keep id_no sympt1 - sympt5 disease; 
retain sympt1 - sympt5 disease; 
array New_a (1:5) $20 sympt1 - sympt5;
disease = 0; 
If first.id_no
then do; 
  do i = 1 to 5; 
    new_a (i) = .; 
  end; 
  new_a (symptom_no) = symptom; 
  if last.id_no then output; 
  if sympt1 ='heartburns' and sympt2='sickness' and sympt3='spasm'
  then disease='1';
  else disease='0'; 
end;
run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I removed the surplus end (which sticks out like a beacon when the code is properly formatted) and the erroneous run.&lt;/P&gt;
&lt;P&gt;Now you can see that your if last. is within the if first. block, and will only be executed if there's only one row per id_no. I guess that's not what yo wanted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Although I'm famous for my notoriously cluttered desk, my codes are always neat and tidy.&lt;/P&gt;</description>
      <pubDate>Sat, 25 Nov 2017 06:55:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-IF-THEN-ELSE-statements-to-create-a-flag-indicating/m-p/416123#M102163</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-11-25T06:55:17Z</dc:date>
    </item>
  </channel>
</rss>

