<?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 If critera is met in any of several variables, create new variable and populate with 'yes' in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/If-critera-is-met-in-any-of-several-variables-create-new/m-p/754648#M238029</link>
    <description>&lt;P&gt;Hello, it has been a while since I've used SAS (using University Edition) and I'm not sure how to go about a problem I'm having.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a cohort of patients, and each patient has had data recorded at 5 visits. At each visit, it's recorded if a referral was needed (1) or not (0). So each patient might have data that looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ref1= 1&lt;/P&gt;&lt;P&gt;ref2=0&lt;/P&gt;&lt;P&gt;ref3=0&lt;/P&gt;&lt;P&gt;ref4=0&lt;/P&gt;&lt;P&gt;ref5=1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to create a new variable (referral) that is populated with 'yes' or 'no' if any one of the ref#=1; so if the patient ever needed a referral, during any visit, the new variable will reflect that.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Right now I am using the following code, but something isn't working. I feel like I need to use an array or DO loops, but like I say, it's been a while. Thank you for your help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA want;&lt;/P&gt;&lt;P&gt;SET have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;IF (ref1-ref5) = .&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; THEN referred = ' ';&lt;/P&gt;&lt;P&gt;ELSE IF (ref1-ref5) = 1 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; THEN referred = ' Yes';&lt;/P&gt;&lt;P&gt;ELSE IF (ref1-ref5) = 0 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; THEN referred = ' No';&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;</description>
    <pubDate>Fri, 16 Jul 2021 18:11:11 GMT</pubDate>
    <dc:creator>anle2079</dc:creator>
    <dc:date>2021-07-16T18:11:11Z</dc:date>
    <item>
      <title>If critera is met in any of several variables, create new variable and populate with 'yes'</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-critera-is-met-in-any-of-several-variables-create-new/m-p/754648#M238029</link>
      <description>&lt;P&gt;Hello, it has been a while since I've used SAS (using University Edition) and I'm not sure how to go about a problem I'm having.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a cohort of patients, and each patient has had data recorded at 5 visits. At each visit, it's recorded if a referral was needed (1) or not (0). So each patient might have data that looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ref1= 1&lt;/P&gt;&lt;P&gt;ref2=0&lt;/P&gt;&lt;P&gt;ref3=0&lt;/P&gt;&lt;P&gt;ref4=0&lt;/P&gt;&lt;P&gt;ref5=1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to create a new variable (referral) that is populated with 'yes' or 'no' if any one of the ref#=1; so if the patient ever needed a referral, during any visit, the new variable will reflect that.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Right now I am using the following code, but something isn't working. I feel like I need to use an array or DO loops, but like I say, it's been a while. Thank you for your help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA want;&lt;/P&gt;&lt;P&gt;SET have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;IF (ref1-ref5) = .&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; THEN referred = ' ';&lt;/P&gt;&lt;P&gt;ELSE IF (ref1-ref5) = 1 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; THEN referred = ' Yes';&lt;/P&gt;&lt;P&gt;ELSE IF (ref1-ref5) = 0 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; THEN referred = ' No';&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Jul 2021 18:11:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-critera-is-met-in-any-of-several-variables-create-new/m-p/754648#M238029</guid>
      <dc:creator>anle2079</dc:creator>
      <dc:date>2021-07-16T18:11:11Z</dc:date>
    </item>
    <item>
      <title>Re: If critera is met in any of several variables, create new variable and populate with 'yes'</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-critera-is-met-in-any-of-several-variables-create-new/m-p/754651#M238032</link>
      <description>&lt;P&gt;You can use an array or DO loop, but this is probably easier to understand and gets the job done.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input pt ref1-ref5;
datalines;
1 1 0 1 1 0
2 1 0 0 0 0
3 0 0 0 0 0
4 0 0 1 0 0
5 1 1 0 0 0
;
run;

data want;
	set have;
	if sum(of ref:) &amp;gt; 0 then referred = "Yes";
		else referred = "No";
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs 	pt 	ref1 	ref2 	ref3 	ref4 	ref5 	referred
1 	1 	1 	0 	1 	1 	0 	Yes
2 	2 	1 	0 	0 	0 	0 	Yes
3 	3 	0 	0 	0 	0 	0 	No
4 	4 	0 	0 	1 	0 	0 	Yes
5 	5 	1 	1 	0 	0 	0 	Yes&lt;/PRE&gt;</description>
      <pubDate>Fri, 16 Jul 2021 18:26:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-critera-is-met-in-any-of-several-variables-create-new/m-p/754651#M238032</guid>
      <dc:creator>maguiremq</dc:creator>
      <dc:date>2021-07-16T18:26:07Z</dc:date>
    </item>
    <item>
      <title>Re: If critera is met in any of several variables, create new variable and populate with 'yes'</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-critera-is-met-in-any-of-several-variables-create-new/m-p/754658#M238039</link>
      <description>&lt;P&gt;Strongly suggest that you use 1/0 coding instead of "Yes" "No".&lt;/P&gt;
&lt;P&gt;You can get counts of "yes" by summing, percent yes by means, if all values are the same with a Range of 0 or any different with a range=1, any yes if Max is 1, a 1/0 coded variable. And a few more tricks.&lt;/P&gt;
&lt;P&gt;The code for a 1/0 coded variable would be&lt;/P&gt;
&lt;P&gt;Referred = max(of ref1-ref5);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to Display "yes" or "no" then create a format that does so:&lt;/P&gt;
&lt;PRE&gt;Proc format;
   value yn
   1='Yes'
   0='No'
   other=' '
  ;
run;&lt;/PRE&gt;
&lt;P&gt;and assign the YN. format just created when you need to see "Yes".&lt;/P&gt;</description>
      <pubDate>Fri, 16 Jul 2021 18:50:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-critera-is-met-in-any-of-several-variables-create-new/m-p/754658#M238039</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-07-16T18:50:23Z</dc:date>
    </item>
    <item>
      <title>Re: If critera is met in any of several variables, create new variable and populate with 'yes'</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-critera-is-met-in-any-of-several-variables-create-new/m-p/754664#M238040</link>
      <description>&lt;P&gt;Why would you make the new variable using a different coding scheme than the original?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;referred = max(of ref1-ref5);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The MAX() over a series of binary variables test if ANY are true.&amp;nbsp; The MIN() tests if ALL are true.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Jul 2021 19:34:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-critera-is-met-in-any-of-several-variables-create-new/m-p/754664#M238040</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-07-16T19:34:47Z</dc:date>
    </item>
  </channel>
</rss>

