<?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: How do I turn variables into values for  a new variable? (part 2 with a twist) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-turn-variables-into-values-for-a-new-variable-part-2/m-p/866150#M342050</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want2;
    set have2;
    length crit $ 200;
    array zzi zzinc:;
    array zze zzexc:;
    crit=' ';
    do i=1 to dim(zzi);
        if zzi(i)='x' then do;
            varname=vname(zzi(i)); 
            crit=cats(crit,', I',substr(varname,6));
        end;
    end;
    do i=1 to dim(zze);
        if zze(i)='x' then do;
            varname=vname(zze(i)); 
            crit=cats(crit,', E',substr(varname,6));
        end;
    end;
    if crit=:',' then crit=substr(crit,2);
    drop i varname;
    keep subject crit;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 24 Mar 2023 15:07:50 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2023-03-24T15:07:50Z</dc:date>
    <item>
      <title>How do I turn variables into values for  a new variable? (part 2 with a twist)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-turn-variables-into-values-for-a-new-variable-part-2/m-p/866146#M342048</link>
      <description>&lt;P&gt;Hi, I posted a question earlier that was answered by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt; , and I got a solution.&lt;/P&gt;
&lt;P&gt;However, this new data set has a twist. Some variables have letters attached to them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The purpose of this is that I was given raw data, and I'm creating an output that condenses information into one variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are 4 subjects, and the "x" represents the value that i want presented in a new variable called CRIT.&lt;/P&gt;
&lt;P&gt;So if zzinc3="x", then CRIT=I3.&lt;/P&gt;
&lt;P&gt;If zzinc2a="x" and zzexc2b="x"&amp;nbsp; and zzexc3="x" then CRIT=I2A, E2B , E3 ** new twist**&lt;/P&gt;
&lt;P&gt;New data with a twist:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have2; 
infile datalines dsd dlm=",";
	input subject $ zzinc1 $ zzinc2a $ zzinc2b $ zzinc2c $ zzinc3 $ zzexc1 $ zzexc2a $ zzexc2b $ zzexc3 $;
datalines;
001, x, x, , x, , , x, , 
002, , x, , , x, , , ,
003, , x, , x, , , , ,
004, , , , , x, , , ,x
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;desired output:&lt;/P&gt;
&lt;P&gt;subject&amp;nbsp;&amp;nbsp;&amp;nbsp; CRIT&lt;/P&gt;
&lt;P&gt;001&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; I1, I2A, I2C, E2A&lt;/P&gt;
&lt;P&gt;002&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; I2A, I3&lt;/P&gt;
&lt;P&gt;003&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; I2A, I2C,&lt;/P&gt;
&lt;P&gt;004&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; I3, E3&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt; 's solution below for part1&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    length crit $ 200;
    array zzi zzinc:;
    array zze zzexc:;
    crit=' ';
    do i=1 to dim(zzi);
        if zzi(i)='x' then crit=cats(crit,', I',i);
    end;
    do i=1 to dim(zze);
        if zze(i)='x' then crit=cats(crit,', E',i);
    end;
    if crit=:',' then crit=substr(crit,2);
    drop i;
    keep subject crit;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;link to part1: &lt;A href="https://communities.sas.com/t5/SAS-Programming/How-do-I-turn-variables-into-values-for-a-new-variable/m-p/866127#M342036" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/SAS-Programming/How-do-I-turn-variables-into-values-for-a-new-variable/m-p/866127#M342036&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Mar 2023 15:01:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-turn-variables-into-values-for-a-new-variable-part-2/m-p/866146#M342048</guid>
      <dc:creator>Hello_there</dc:creator>
      <dc:date>2023-03-24T15:01:34Z</dc:date>
    </item>
    <item>
      <title>Re: How do I turn variables into values for  a new variable? (part 2 with a twist)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-turn-variables-into-values-for-a-new-variable-part-2/m-p/866150#M342050</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want2;
    set have2;
    length crit $ 200;
    array zzi zzinc:;
    array zze zzexc:;
    crit=' ';
    do i=1 to dim(zzi);
        if zzi(i)='x' then do;
            varname=vname(zzi(i)); 
            crit=cats(crit,', I',substr(varname,6));
        end;
    end;
    do i=1 to dim(zze);
        if zze(i)='x' then do;
            varname=vname(zze(i)); 
            crit=cats(crit,', E',substr(varname,6));
        end;
    end;
    if crit=:',' then crit=substr(crit,2);
    drop i varname;
    keep subject crit;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 Mar 2023 15:07:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-turn-variables-into-values-for-a-new-variable-part-2/m-p/866150#M342050</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-03-24T15:07:50Z</dc:date>
    </item>
    <item>
      <title>Re: How do I turn variables into values for  a new variable? (part 2 with a twist)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-turn-variables-into-values-for-a-new-variable-part-2/m-p/866157#M342052</link>
      <description>Thanks, PaigeMiller. Very helpful!</description>
      <pubDate>Fri, 24 Mar 2023 15:14:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-turn-variables-into-values-for-a-new-variable-part-2/m-p/866157#M342052</guid>
      <dc:creator>Hello_there</dc:creator>
      <dc:date>2023-03-24T15:14:54Z</dc:date>
    </item>
  </channel>
</rss>

