<?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 Combine variables into one in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Combine-variables-into-one/m-p/778864#M247984</link>
    <description>&lt;P&gt;I have several insurance variables that&amp;nbsp;are coded as 1 if someone chose those insurances in a survey (i.e., Medicare, Medicaid, COBRA etc.).&lt;/P&gt;&lt;P&gt;For example, Medicaid in a proc freq looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Medicaid&amp;nbsp; &amp;nbsp; Frequency&amp;nbsp; &amp;nbsp; &amp;nbsp;Percent&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;59&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 100.0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to create a new variable that combines all my insurance variables. How do I go about doing this? I'm pretty stuck.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 05 Nov 2021 18:58:17 GMT</pubDate>
    <dc:creator>westbestern</dc:creator>
    <dc:date>2021-11-05T18:58:17Z</dc:date>
    <item>
      <title>Combine variables into one</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-variables-into-one/m-p/778864#M247984</link>
      <description>&lt;P&gt;I have several insurance variables that&amp;nbsp;are coded as 1 if someone chose those insurances in a survey (i.e., Medicare, Medicaid, COBRA etc.).&lt;/P&gt;&lt;P&gt;For example, Medicaid in a proc freq looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Medicaid&amp;nbsp; &amp;nbsp; Frequency&amp;nbsp; &amp;nbsp; &amp;nbsp;Percent&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;59&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 100.0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to create a new variable that combines all my insurance variables. How do I go about doing this? I'm pretty stuck.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Nov 2021 18:58:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-variables-into-one/m-p/778864#M247984</guid>
      <dc:creator>westbestern</dc:creator>
      <dc:date>2021-11-05T18:58:17Z</dc:date>
    </item>
    <item>
      <title>Re: Combine variables into one</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-variables-into-one/m-p/778869#M247986</link>
      <description>&lt;P&gt;What do you want it to look like???&lt;/P&gt;
&lt;P&gt;Is the result supposed to be numeric or character?&lt;/P&gt;
&lt;P&gt;How many variables are there?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think that you need to provide a few worked examples with at least a few variables. It may also help to describe how you intend to use that variable later for suggestions.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Nov 2021 19:19:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-variables-into-one/m-p/778869#M247986</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-11-05T19:19:27Z</dc:date>
    </item>
    <item>
      <title>Re: Combine variables into one</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-variables-into-one/m-p/778871#M247988</link>
      <description>&lt;P&gt;Are these dichotomous fields? Also, are they mutually exclusive?&lt;/P&gt;
&lt;P&gt;I made some fake data under these assumptions:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input pt medicaid medicare cobra private 3.;
datalines;
1 1 0 0 0
2 0 1 0 0
3 0 0 1 0
4 0 0 0 1
5 0 0 1 0
6 0 0 0 1
;
run;

data want;
	set have;
	array _ins [*] medicaid -- private;
	do i = 1 to dim(_ins);
		if _ins[i] = 1 then insurance = vname(_ins[i]);
	end;
run;
	&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs 	pt 	medicaid 	medicare 	cobra 	private 	i 	insurance
1 	1 	1 	0 	0 	0 	5 	medicaid
2 	2 	0 	1 	0 	0 	5 	medicare
3 	3 	0 	0 	1 	0 	5 	cobra
4 	4 	0 	0 	0 	1 	5 	private
5 	5 	0 	0 	1 	0 	5 	cobra
6 	6 	0 	0 	0 	1 	5 	private&lt;/PRE&gt;
&lt;P&gt;It's always a good habit to post example data that shows us your exact problem. See&amp;nbsp;&lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;here.&lt;/A&gt; If it contains PHI or PII, try to emulate it with fake data as I did above.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Nov 2021 19:22:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-variables-into-one/m-p/778871#M247988</guid>
      <dc:creator>maguiremq</dc:creator>
      <dc:date>2021-11-05T19:22:47Z</dc:date>
    </item>
    <item>
      <title>Re: Combine variables into one</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-variables-into-one/m-p/778872#M247989</link>
      <description>&lt;P&gt;These are all character variables. I want to run a bivariate analysis on the association between insurance variables and PrEP usage without going through all the insurances individually. Basically, does have insurance influence PrEP usage? There are 11 insurance variables.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Nov 2021 19:22:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-variables-into-one/m-p/778872#M247989</guid>
      <dc:creator>westbestern</dc:creator>
      <dc:date>2021-11-05T19:22:48Z</dc:date>
    </item>
    <item>
      <title>Re: Combine variables into one</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-variables-into-one/m-p/778880#M247993</link>
      <description>&lt;P&gt;I think you are looking for a statement to add to a DATA step, such as:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;have_insurance = (cobra="1") or (medicaid="1") or (medicare="1");&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Extend the list to include all 11 types of insurance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HAVE_INSURANCE will be numeric, with a value of 1 or 0.&amp;nbsp; When any type of insurance types exists, it will be 1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This assumes (as you stated) that all the insurance fields are character.&amp;nbsp; If they are actually numeric, the quotes should be removed.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Nov 2021 20:22:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-variables-into-one/m-p/778880#M247993</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2021-11-05T20:22:33Z</dc:date>
    </item>
    <item>
      <title>Re: Combine variables into one</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-variables-into-one/m-p/778977#M248037</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/400922"&gt;@westbestern&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's an nice solution demonstrated by 3 variables (you can extend to any number you like):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data a;&lt;BR /&gt;x1='0'; x2='0'; x3='0'; z = ifn(catt(of x1-x3)='000',0,1); output;&lt;BR /&gt;x1='1'; x2='0'; x3='0'; z = ifn(catt(of x1-x3)='000',0,1); output;&lt;BR /&gt;x1='1'; x2='1'; x3='0'; z = ifn(catt(of x1-x3)='000',0,1); output;&lt;BR /&gt;x1='0'; x2='0'; x3='1'; z = ifn(catt(of x1-x3)='000',0,1); output;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Eyal&lt;/P&gt;</description>
      <pubDate>Sun, 07 Nov 2021 11:21:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-variables-into-one/m-p/778977#M248037</guid>
      <dc:creator>EyalGonen</dc:creator>
      <dc:date>2021-11-07T11:21:22Z</dc:date>
    </item>
    <item>
      <title>Re: Combine variables into one</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-variables-into-one/m-p/779183#M248135</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/400922"&gt;@westbestern&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;These are all character variables. I want to run a bivariate analysis on the association between insurance variables and PrEP usage without going through all the insurances individually. Basically, does have insurance influence PrEP usage? There are 11 insurance variables.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I would do something similar to&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want;
     set have;
     array ins(*) &amp;lt;list the names of your insurance variables here&amp;gt;;
    have_ins = (index(cats(of ins(*)),'1')&amp;gt;0);
end;&lt;/PRE&gt;
&lt;P&gt;The CATS function concatenates all the values of the variables in the array, the Index function returns the first position of the character 1, if present or 0 other wise. SAS will return a numeric 1 for that index value greater than 0 or 0 otherwise.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Suggestion for future stuff. If your variables are dichotomous, such as "has this characteristic/does not have" then coding them as 1/0 (have, don't have; true/false; yes/no) numeric variables is more flexible than character.&lt;/P&gt;
&lt;P&gt;Max(of array(*)) would return 1 if any were 1(present/true whatever) or 0 if none were.&lt;/P&gt;
&lt;P&gt;Sum(of array(*)) tells you how many had a 1&lt;/P&gt;
&lt;P&gt;Mean(of array(*)) tells you the percent of 1 were present&amp;nbsp; (.8 = 80%)&lt;/P&gt;
&lt;P&gt;Min(of array(*)) =1 tells you all the values were 1&lt;/P&gt;
&lt;P&gt;Range(of array(*)) =1 tells you at least one value was 0 and at least one was 1, a range of 0 tells you all the values were the same.&lt;/P&gt;
&lt;P&gt;With character values a tad more coding would be needed for most of these, especially percentages.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Nov 2021 18:26:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-variables-into-one/m-p/779183#M248135</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-11-08T18:26:02Z</dc:date>
    </item>
  </channel>
</rss>

