<?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? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-turn-variables-into-values-for-a-new-variable/m-p/866126#M342036</link>
    <description>&lt;P&gt;I ask my usual question ... why are you doing this, what can you do with data in CRIT that you can't do with data in the original form? Often, people think that converting the data to a new form makes things easier, but I am always skeptical. It might be easier, or it might not be, depending on the next step, and you didn't tell us what happens next.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyway, here is code to convert the data&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&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;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 24 Mar 2023 13:45:11 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2023-03-24T13:45:11Z</dc:date>
    <item>
      <title>How do I turn variables into values for a new variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-turn-variables-into-values-for-a-new-variable/m-p/866105#M342034</link>
      <description>&lt;P&gt;Hi, I'm trying to use the variables in this data as values for a new variable i'm trying to create.&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 zzinc3="x", zzinc10="x", and zzexc7="x" then CRIT=I3, I10, E7&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have; 
infile datalines dsd dlm=",";
	input subject $ zzinc1 $ zzinc2 $ zzinc3 $ zzinc4 $ zzinc5 $ zzinc6 $ zzinc7 $ zzinc8 $ zzinc9 $ zzinc10 $ zzinc11 $ zzexc1 $ zzexc2 $ zzexc3 $ zzexc4 $ zzexc5 $ zzexc6 $ zzex7 $;
datalines;
001, , , x, , , , , , , x, x, , , , , x, x, 
002, x, , , , x, x, , , , , , , x, , , x, ,
003, , x, x, , , , , , , , , , , , x, , , 
004, , , , , , , , , , , , , , , , , ,  
;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Desired output:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;subject&amp;nbsp;&amp;nbsp;&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;&amp;nbsp;&amp;nbsp; I3, I10, I11, E5, E6&lt;/P&gt;
&lt;P&gt;002&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; I1, I5, I6,&amp;nbsp; E2, E5&lt;/P&gt;
&lt;P&gt;003&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; I2, I3, E4&lt;/P&gt;
&lt;P&gt;004&lt;/P&gt;</description>
      <pubDate>Fri, 24 Mar 2023 13:19:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-turn-variables-into-values-for-a-new-variable/m-p/866105#M342034</guid>
      <dc:creator>Hello_there</dc:creator>
      <dc:date>2023-03-24T13:19:29Z</dc:date>
    </item>
    <item>
      <title>Re: How do I turn variables into values for a new variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-turn-variables-into-values-for-a-new-variable/m-p/866126#M342036</link>
      <description>&lt;P&gt;I ask my usual question ... why are you doing this, what can you do with data in CRIT that you can't do with data in the original form? Often, people think that converting the data to a new form makes things easier, but I am always skeptical. It might be easier, or it might not be, depending on the next step, and you didn't tell us what happens next.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyway, here is code to convert the data&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&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;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 Mar 2023 13:45:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-turn-variables-into-values-for-a-new-variable/m-p/866126#M342036</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-03-24T13:45:11Z</dc:date>
    </item>
    <item>
      <title>Re: How do I turn variables into values for a new variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-turn-variables-into-values-for-a-new-variable/m-p/866127#M342037</link>
      <description>Hi PaigeMiller, &lt;BR /&gt;This is how the raw data is presented to me, and I'm creating an output that summarizes a list of those variables marked "x", because they represent criterias that were not met for each subject. It is better to present it is a comma-separated list condensed into one variable, rather than all 18 variables be presented. The desired output is the final step.&lt;BR /&gt;&lt;BR /&gt;Thanks for your help!</description>
      <pubDate>Fri, 24 Mar 2023 13:48:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-turn-variables-into-values-for-a-new-variable/m-p/866127#M342037</guid>
      <dc:creator>Hello_there</dc:creator>
      <dc:date>2023-03-24T13:48:46Z</dc:date>
    </item>
  </channel>
</rss>

