<?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: Extract VARIABLE NAME and concatenate with other variable names based on condition in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Extract-VARIABLE-NAME-and-concatenate-with-other-variable-names/m-p/551351#M153174</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt; , thanks for your respons. I tested the code on sashelp.class and seem like it is working. Appreciate your thoughts. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set sashelp.class;
array var1(*) age height weight ;
array var2(*)$ agec heightc weightc;
do i = 1 to dim(var1);
if var1(i) ne . then var2(i)=vname(var1(i));
newvar=catx(',',of var2(*));
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 16 Apr 2019 11:51:54 GMT</pubDate>
    <dc:creator>Jagadishkatam</dc:creator>
    <dc:date>2019-04-16T11:51:54Z</dc:date>
    <item>
      <title>Extract VARIABLE NAME and concatenate with other variable names based on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-VARIABLE-NAME-and-concatenate-with-other-variable-names/m-p/550801#M152954</link>
      <description>&lt;P&gt;I have a dataset that looks like this&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;currentstudy Study1ID&amp;nbsp; &amp;nbsp; &amp;nbsp;Study2ID&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Study3ID&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Study4ID&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; 180&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 780&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 278&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;560&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; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 790&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;520&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; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 231&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As you can see, each patient can be enrolled on multiple other studies.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I need is a dataset that looks like below.&lt;/P&gt;
&lt;P&gt;Basically, concatenate the column names/study names of the other studies that same patient is enrolled in.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;currentstudy&amp;nbsp; Other_enrolled_studies&amp;nbsp;&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;Study1,Study2,Study3,Study4&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;Study2,Study4&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;Study 3&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and so on for several hundred patients across multiple studies.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks very much,&lt;/P&gt;
&lt;P&gt;Please help.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Apr 2019 22:31:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-VARIABLE-NAME-and-concatenate-with-other-variable-names/m-p/550801#M152954</guid>
      <dc:creator>saslove</dc:creator>
      <dc:date>2019-04-12T22:31:26Z</dc:date>
    </item>
    <item>
      <title>Re: Extract VARIABLE NAME and concatenate with other variable names based on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-VARIABLE-NAME-and-concatenate-with-other-variable-names/m-p/550804#M152955</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;

length studies $200;

array study(*) study: ;

do i=1 to dim(study);

if not missing(study(i)) then do;
      studies = catx(", ", studies, vname(study(i)));
end;

run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;1. Declare an array of all studys&lt;/P&gt;
&lt;P&gt;2. Loop through and find non missing entries&lt;/P&gt;
&lt;P&gt;3. Find variable name (vname)&lt;/P&gt;
&lt;P&gt;4. append to list of 'studies'&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/1717"&gt;@saslove&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have a dataset that looks like this&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;currentstudy Study1ID&amp;nbsp; &amp;nbsp; &amp;nbsp;Study2ID&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Study3ID&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Study4ID&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; 180&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 780&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 278&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;560&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; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 790&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;520&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; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 231&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As you can see, each patient can be enrolled on multiple other studies.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I need is a dataset that looks like below.&lt;/P&gt;
&lt;P&gt;Basically, concatenate the column names/study names of the other studies that same patient is enrolled in.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;currentstudy&amp;nbsp; Other_enrolled_studies&amp;nbsp;&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;Study1,Study2,Study3,Study4&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;Study2,Study4&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;Study 3&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and so on for several hundred patients across multiple studies.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks very much,&lt;/P&gt;
&lt;P&gt;Please help.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Apr 2019 22:35:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-VARIABLE-NAME-and-concatenate-with-other-variable-names/m-p/550804#M152955</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-04-12T22:35:04Z</dc:date>
    </item>
    <item>
      <title>Re: Extract VARIABLE NAME and concatenate with other variable names based on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-VARIABLE-NAME-and-concatenate-with-other-variable-names/m-p/550807#M152957</link>
      <description>&lt;P&gt;That worked very well. Thanks Reeza&lt;/P&gt;</description>
      <pubDate>Fri, 12 Apr 2019 22:44:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-VARIABLE-NAME-and-concatenate-with-other-variable-names/m-p/550807#M152957</guid>
      <dc:creator>saslove</dc:creator>
      <dc:date>2019-04-12T22:44:36Z</dc:date>
    </item>
    <item>
      <title>Re: Extract VARIABLE NAME and concatenate with other variable names based on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-VARIABLE-NAME-and-concatenate-with-other-variable-names/m-p/550834#M152970</link>
      <description>&lt;P&gt;An alternative way&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
array var1(*) Study1ID Study2ID Study3ID Study4ID;
array var2(*)$ Study1IDc Study2IDc Study3IDc Study4IDc;
do i = 1 to dim(var1);
if var1(i) ne . then var2(i)=vname(var1(i));
newvar=catx(',',of var2(*));
end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 13 Apr 2019 08:29:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-VARIABLE-NAME-and-concatenate-with-other-variable-names/m-p/550834#M152970</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2019-04-13T08:29:39Z</dc:date>
    </item>
    <item>
      <title>Re: Extract VARIABLE NAME and concatenate with other variable names based on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-VARIABLE-NAME-and-concatenate-with-other-variable-names/m-p/551287#M153161</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12151"&gt;@Jagadishkatam&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;An alternative way&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
array var1(*) Study1ID Study2ID Study3ID Study4ID;
array var2(*)$ Study1IDc Study2IDc Study3IDc Study4IDc;
do i = 1 to dim(var1);
if var1(i) ne . then var2(i)=vname(var1(i));
newvar=catx(',',of var2(*));
end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12151"&gt;@Jagadishkatam&lt;/a&gt;&amp;nbsp;should the newer line be outside of the loop?&lt;/P&gt;</description>
      <pubDate>Tue, 16 Apr 2019 01:06:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-VARIABLE-NAME-and-concatenate-with-other-variable-names/m-p/551287#M153161</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-04-16T01:06:50Z</dc:date>
    </item>
    <item>
      <title>Re: Extract VARIABLE NAME and concatenate with other variable names based on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-VARIABLE-NAME-and-concatenate-with-other-variable-names/m-p/551351#M153174</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt; , thanks for your respons. I tested the code on sashelp.class and seem like it is working. Appreciate your thoughts. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set sashelp.class;
array var1(*) age height weight ;
array var2(*)$ agec heightc weightc;
do i = 1 to dim(var1);
if var1(i) ne . then var2(i)=vname(var1(i));
newvar=catx(',',of var2(*));
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 Apr 2019 11:51:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-VARIABLE-NAME-and-concatenate-with-other-variable-names/m-p/551351#M153174</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2019-04-16T11:51:54Z</dc:date>
    </item>
    <item>
      <title>Re: Extract VARIABLE NAME and concatenate with other variable names based on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-VARIABLE-NAME-and-concatenate-with-other-variable-names/m-p/551393#M153187</link>
      <description>Technically it works, because it gets replaced at each iteration of the I loop, including the last, which is the same as doing it after the loop is finished. It's just not really logical to do it when it's not needed. If the data set is small this has no impact, if the data set is larger it's an inefficiency that slows things down.</description>
      <pubDate>Tue, 16 Apr 2019 14:52:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-VARIABLE-NAME-and-concatenate-with-other-variable-names/m-p/551393#M153187</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-04-16T14:52:18Z</dc:date>
    </item>
  </channel>
</rss>

