<?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: Array to loop column name variable wide to long in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Array-to-loop-column-name-variable-wide-to-long/m-p/297558#M62501</link>
    <description>&lt;P&gt;What are you having trouble with? &amp;nbsp;Looks simple to me.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
  length MONITER_ID $8 DATE_REC 8
         A_STATUS $8 A_ID 8 B_STATUS $8 B_ID 8 C_STATUS $8 C_ID 8
         ARC_NAM $8 ARC_DAT 8
  ;
  informat date_rec arc_dat mmddyy10.;
  format date_rec arc_dat yymmdd10.;
  input moniter_id -- arc_dat ;
cards;
MONI_ID1 2/3/2016 YES  1 NO  2 YES  5 ADAM 3/9/2016
MONI_ID2 3/3/2016 NO  2 YES  3 YES  6 KAN 8/9/2016
MONI_ID3 4/3/2016 NO  3 Complete 1 complete 7 KAN 9/9/2016
MONI_ID4 6/3/2016 YES  4 NO  2 YEs  8 ADAM 10/9/2016
;
data want ;
 set have ;
 array stat A_STATUS B_STATUS C_STATUS ;
 array id   A_ID B_ID C_ID ;
 do i=1 to dim(stat);
   length status $32 ;
   status = vname(stat(i));
   value = stat(i);
   id_code = id(i);
   output;
 end;
 keep moniter_id status value id_code ;
run;

proc print; run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 11 Sep 2016 00:02:15 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2016-09-11T00:02:15Z</dc:date>
    <item>
      <title>Array to loop column name variable wide to long</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-to-loop-column-name-variable-wide-to-long/m-p/297486#M62473</link>
      <description>&lt;P&gt;I am finding difficulty in assigning column name variables to array list. I am trying to create a new dataset with&amp;nbsp;column lable name in a field(NEW_COLUMN1) and column value(&lt;SPAN&gt;NEW_COLUMN2)&lt;/SPAN&gt;&amp;nbsp;in another field. Given below is the code which I have tried&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.dataset_new;
set work.dataset_created;
LENGTH NEW_COLUMN1 $ 100;
FORMAT NEW_COLUMN2 6.;
Array char {*} _character_;
Array num {*} _numeric_;
do i = 1 to dim(char); 
NEW_COLUMN1 = vlabel(char{i});
NEW_COLUMN2 = (char{i});
end;
do i = 1 to dim(num); 
NEW_COLUMN1 = vlabel(char{i});
NEW_COLUMN2 = (char{i});
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Actual_dataset:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;COLUMN1 COLUMN2 COLUMN3 COLUMN4 COLUMN5 COLUMN6 COLUMN7 COLUMN8 COLUMN9&lt;/P&gt;&lt;P&gt;101 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 102 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 103 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;104 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;105 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 106 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;22 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 55 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Expected dataset&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;NEW_COLUMN1 &amp;nbsp; &amp;nbsp; &amp;nbsp; NEW_COLUMN2&lt;BR /&gt;COLUMN6_label &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;106&lt;BR /&gt;COLUMN7&lt;SPAN&gt;_label &amp;nbsp; &lt;/SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&lt;BR /&gt;COLUMN8&lt;SPAN&gt;_label &amp;nbsp; &lt;/SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;22 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Sep 2016 20:42:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-to-loop-column-name-variable-wide-to-long/m-p/297486#M62473</guid>
      <dc:creator>jayakumarmm</dc:creator>
      <dc:date>2016-09-09T20:42:16Z</dc:date>
    </item>
    <item>
      <title>Re: Array to loop column name variable wide to long</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-to-loop-column-name-variable-wide-to-long/m-p/297490#M62474</link>
      <description>&lt;P&gt;Sounds like a simple transpose.&lt;/P&gt;
&lt;P&gt;Let's assume you have this dataset. We can call it HAVE.;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input COLUMN1-COLUMN9;&lt;BR /&gt;  label column1='This is what a label looks like';
cards;
101 102 103 104 105 106 3 22 55
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now you want to create a tall skinny table with name/label/value pairs instead.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  set have;
  array all _numeric_;
  length name $32 label $256 value 8;
  do i=1 to dim(all);
    name=vname(all(i));
    label=vlabel(all(i));
    value = all(i);
    output;
  end;
  keep name label value;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Here is the result.&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/4881i5388181FF6EC5243/image-size/original?v=v2&amp;amp;px=-1" border="0" alt="Capture.PNG" title="Capture.PNG" /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Sep 2016 21:04:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-to-loop-column-name-variable-wide-to-long/m-p/297490#M62474</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-09-09T21:04:15Z</dc:date>
    </item>
    <item>
      <title>Re: Array to loop column name variable wide to long</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-to-loop-column-name-variable-wide-to-long/m-p/297500#M62479</link>
      <description>&lt;P&gt;Thanks a lot for your soluton it saved me lot of typing. I have a&amp;nbsp;clarificaton in selecting the variables based on variable name&amp;nbsp;postion and ignoring few variables based on variable names.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example: Ignore variable name looks like below code and ike to know another logic i.e. &amp;nbsp;how to consider variable names in the array between two variables names COLUMN5 - COLUMN9 and drop &amp;nbsp;&lt;SPAN&gt;COLUMN5 &amp;amp;&amp;nbsp;COLUMN9 from dataset&lt;/SPAN&gt;&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 all _numeric_;
  length name $32 label $256 value 8;
  do i=1 to dim(all);
&lt;STRONG&gt;    IF vname(all(i))  not like 'Sc%' then
do;&lt;/STRONG&gt;
    name=vname(all(i));
    label=vlabel(all(i));
    value = all(i);
    output;
&lt;STRONG&gt;  end;&lt;/STRONG&gt;
end;
  keep name label value;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Sep 2016 21:57:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-to-loop-column-name-variable-wide-to-long/m-p/297500#M62479</guid>
      <dc:creator>jayakumarmm</dc:creator>
      <dc:date>2016-09-09T21:57:07Z</dc:date>
    </item>
    <item>
      <title>Re: Array to loop column name variable wide to long</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-to-loop-column-name-variable-wide-to-long/m-p/297504#M62483</link>
      <description>&lt;P&gt;See SAS Variable Lists for ways to list variables:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lrcon/68089/HTML/default/viewer.htm#p0wphcpsfgx6o7n1sjtqzizp1n39.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrcon/68089/HTML/default/viewer.htm#p0wphcpsfgx6o7n1sjtqzizp1n39.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Sep 2016 22:06:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-to-loop-column-name-variable-wide-to-long/m-p/297504#M62483</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-09-09T22:06:59Z</dc:date>
    </item>
    <item>
      <title>Re: Array to loop column name variable wide to long</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-to-loop-column-name-variable-wide-to-long/m-p/297510#M62487</link>
      <description>&lt;P&gt;If there are not a lot variables you may be better off to explicitly list then instead of using like.&lt;/P&gt;
&lt;P&gt;Instead of&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token keyword"&gt;IF&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;vname&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;all&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;i&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&amp;nbsp; &lt;SPAN class="token operator"&gt;not&lt;/SPAN&gt; like &lt;SPAN class="token string"&gt;'Sc%'&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;then &lt;/SPAN&gt;do&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token punctuation"&gt;&lt;SPAN class="token keyword"&gt;IF&lt;/SPAN&gt; upcase(&lt;SPAN class="token function"&gt;vname&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;all&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;i&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;))&lt;/SPAN&gt;&amp;nbsp; &lt;SPAN class="token operator"&gt;not&lt;/SPAN&gt;&amp;nbsp;in ('COLUMN5' 'COLUMN9')&amp;nbsp;&lt;SPAN class="token keyword"&gt;then &lt;/SPAN&gt;do&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Sep 2016 23:09:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-to-loop-column-name-variable-wide-to-long/m-p/297510#M62487</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-09-09T23:09:04Z</dc:date>
    </item>
    <item>
      <title>Re: Array to loop column name variable wide to long</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-to-loop-column-name-variable-wide-to-long/m-p/297555#M62499</link>
      <description>&lt;P&gt;I am struggling for 4 to 5 hrs &amp;nbsp;to build a dataset in SAS , I have attached the current and expected dataset. Now I am need of expertise advise.&lt;/P&gt;</description>
      <pubDate>Sat, 10 Sep 2016 22:55:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-to-loop-column-name-variable-wide-to-long/m-p/297555#M62499</guid>
      <dc:creator>jayakumarmm</dc:creator>
      <dc:date>2016-09-10T22:55:41Z</dc:date>
    </item>
    <item>
      <title>Re: Array to loop column name variable wide to long</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-to-loop-column-name-variable-wide-to-long/m-p/297558#M62501</link>
      <description>&lt;P&gt;What are you having trouble with? &amp;nbsp;Looks simple to me.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
  length MONITER_ID $8 DATE_REC 8
         A_STATUS $8 A_ID 8 B_STATUS $8 B_ID 8 C_STATUS $8 C_ID 8
         ARC_NAM $8 ARC_DAT 8
  ;
  informat date_rec arc_dat mmddyy10.;
  format date_rec arc_dat yymmdd10.;
  input moniter_id -- arc_dat ;
cards;
MONI_ID1 2/3/2016 YES  1 NO  2 YES  5 ADAM 3/9/2016
MONI_ID2 3/3/2016 NO  2 YES  3 YES  6 KAN 8/9/2016
MONI_ID3 4/3/2016 NO  3 Complete 1 complete 7 KAN 9/9/2016
MONI_ID4 6/3/2016 YES  4 NO  2 YEs  8 ADAM 10/9/2016
;
data want ;
 set have ;
 array stat A_STATUS B_STATUS C_STATUS ;
 array id   A_ID B_ID C_ID ;
 do i=1 to dim(stat);
   length status $32 ;
   status = vname(stat(i));
   value = stat(i);
   id_code = id(i);
   output;
 end;
 keep moniter_id status value id_code ;
run;

proc print; run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 11 Sep 2016 00:02:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-to-loop-column-name-variable-wide-to-long/m-p/297558#M62501</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-09-11T00:02:15Z</dc:date>
    </item>
  </channel>
</rss>

