<?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: Merging Variables in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Merging-Variables/m-p/712482#M27054</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if time0person='Yes' or Most0person='yes' then visit_type_Time0= "in-person";
else if Time0tele='Yes' or Most0tele='Yes' then visit_type_Time0="telehealth";
else if time0phone='Yes' or Most0phone='Yes' then visit_Time0="phone";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;What is wrong with the above code that makes you ask if it is possible?&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 19 Jan 2021 19:12:34 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2021-01-19T19:12:34Z</dc:date>
    <item>
      <title>Merging Variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Merging-Variables/m-p/712475#M27051</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I was wondering if the if/else statements in SAS can be used with "or" to merge multiple variables. For instance, if using the following code:&lt;/P&gt;&lt;P&gt;if time0person='Yes' then visit_type_Time0= "in-person";&lt;BR /&gt;else if Time0tele='Yes' then visit_type_Time0="telehealth";&lt;BR /&gt;else if time0phone='Yes' then visit_Time0="phone";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have another 3 variables called Most0person, most0tele, and most0phone. is there some way to combine all 'Yes" answers for time0person with all 'Yes' answers for Most0person into the same variable "Visit_type_0"="in-person"?&lt;/P&gt;&lt;P&gt;Something like&amp;nbsp;&lt;/P&gt;&lt;P&gt;if time0person='Yes' or Most0person='yes' then visit_type_Time0= "in-person";&lt;BR /&gt;else if Time0tele='Yes' or Most0tele='Yes' then visit_type_Time0="telehealth";&lt;BR /&gt;else if time0phone='Yes' or Most0phone='Yes' then visit_Time0="phone";&lt;/P&gt;&lt;P&gt;Please let me know if this question makes sense. Thanks.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jan 2021 18:58:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Merging-Variables/m-p/712475#M27051</guid>
      <dc:creator>lawye010</dc:creator>
      <dc:date>2021-01-19T18:58:13Z</dc:date>
    </item>
    <item>
      <title>Re: Merging Variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Merging-Variables/m-p/712482#M27054</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if time0person='Yes' or Most0person='yes' then visit_type_Time0= "in-person";
else if Time0tele='Yes' or Most0tele='Yes' then visit_type_Time0="telehealth";
else if time0phone='Yes' or Most0phone='Yes' then visit_Time0="phone";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;What is wrong with the above code that makes you ask if it is possible?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jan 2021 19:12:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Merging-Variables/m-p/712482#M27054</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-01-19T19:12:34Z</dc:date>
    </item>
    <item>
      <title>Re: Merging Variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Merging-Variables/m-p/712496#M27055</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/363694"&gt;@lawye010&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I was wondering if the if/else statements in SAS can be used with "or" to merge multiple variables. For instance, if using the following code:&lt;/P&gt;
&lt;P&gt;if time0person='Yes' then visit_type_Time0= "in-person";&lt;BR /&gt;else if Time0tele='Yes' then visit_type_Time0="telehealth";&lt;BR /&gt;else if time0phone='Yes' then visit_Time0="phone";&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have another 3 variables called Most0person, most0tele, and most0phone. is there some way to combine all 'Yes" answers for time0person with all 'Yes' answers for Most0person into the same variable "Visit_type_0"="in-person"?&lt;/P&gt;
&lt;P&gt;Something like&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if time0person='Yes' or Most0person='yes' then visit_type_Time0= "in-person";&lt;BR /&gt;else if Time0tele='Yes' or Most0tele='Yes' then visit_type_Time0="telehealth";&lt;BR /&gt;else if time0phone='Yes' or Most0phone='Yes' then visit_Time0="phone";&lt;/P&gt;
&lt;P&gt;Please let me know if this question makes sense. Thanks.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If this were my data I would say you are incomplete. You do not have any value assigned to Visit_type_Time0 if all of the 4 variables used are "no". That might be an issue in some forms of analysis.&lt;/P&gt;
&lt;P&gt;Like when you run a simple frequency on the variable and the number of observations do not match the number of records. So the percentages may be skewed. The more often none of the variables are yes the more significant this issue might become.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By the way, coding as "yes" "no" with character values is making you code more complex than needed if those are the only two possible values. SAS will treat a numeric value of 1 (actually pretty much anything other than 0 and missing) as "true" and 0 as false.&lt;/P&gt;
&lt;P&gt;So creating 1/0 coded variables would allow writing code like:&lt;/P&gt;
&lt;PRE&gt;if time0person or Most0person then visit_type_Time0= "in-person";
else if Time0tele or Most0tele then visit_type_Time0="telehealth";&lt;/PRE&gt;
&lt;P&gt;Another potential advantage of 1/0 coding is that a sum of the variable becomes the count of 1 (or Yes), the mean is a percentage of 1 as a decimal.&lt;/P&gt;
&lt;P&gt;And when you have multiple variables you can use some of the other functions such as max, min with them.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jan 2021 20:29:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Merging-Variables/m-p/712496#M27055</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-01-19T20:29:24Z</dc:date>
    </item>
    <item>
      <title>Re: Merging Variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Merging-Variables/m-p/712521#M27057</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/363694"&gt;@lawye010&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I agree with &lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884" target="_blank" rel="noopener"&gt;ballardw&lt;/A&gt; that 1/0 coded Yes/No variables are more convenient. Either way, coding&amp;nbsp;IF-THEN/ELSE statements can be boring at times and also prone to typos (cf. &lt;FONT face="courier new,courier"&gt;'yes'&lt;/FONT&gt; vs. &lt;FONT face="courier new,courier"&gt;'Yes'&lt;/FONT&gt; and&amp;nbsp;&lt;SPAN&gt;&lt;FONT face="courier new,courier"&gt;visit_Time0&lt;/FONT&gt; vs.&amp;nbsp;&lt;FONT face="courier new,courier"&gt;visit_type_Time0&lt;/FONT&gt;). You can avoid repetitions (and make your work more interesting &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; ) by using arrays and SAS functions.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Example (using character variables)&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input (Time0person Most0person Time0tele Most0tele Time0phone Most0phone) (:$3.);
cards;
No Yes Yes Yes No  No
No No  Yes No  Yes No
No No  No  No  No  Yes
No No  No  No  No  No
;

data want;
set have;
array vt[0:6] $10 _temporary_ (' ' 2*'in-person' 2*'telehealth' 2*'phone');
array tm[*] Time0person--Most0phone;
visit_type_time0=vt[whichc('Yes', of tm[*])];
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;To make the comparison case-insensitive, you can use something like&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;visit_type_time0=vt[(find(cat(of tm[*]),'yes','i')-1)/3+1];&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 19 Jan 2021 21:30:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Merging-Variables/m-p/712521#M27057</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-01-19T21:30:39Z</dc:date>
    </item>
  </channel>
</rss>

