<?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: COLUMN INSERT BETWEEN TO VARIABLE COLUMNS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/COLUMN-INSERT-BETWEEN-TO-VARIABLE-COLUMNS/m-p/484608#M125822</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/224531"&gt;@dane77221&lt;/a&gt;:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I like the elegance of the solution&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp;has offered. But since you said you want to specify nothing but the names of the surrounding variables, I'd offer one where you need to name only the variable &lt;EM&gt;after&lt;/EM&gt; which you want the insertion (and, of course, necessarily the name and other attributes of the variable you want to insert). Thus, if you originally have a data set:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;                                             
  retain A "A" B "BB" C "CCC" E "EEEEE" F "FFFFFF" G 1 ;
  do G = 1 to 10 ;                                      
    output ;                                            
  end ;                                                 
run ;                                                   &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;and want to insert a variable D after variable C, you could code as follows:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let v_aft =  C ;                                                        
%let v_ins =  D ;                                                        
%let v_len = $4 ; * if you want D as numeric, just code 8 instead of $4 ;
                                                                         
data _null_ ;                                                            
  do until (z) ;                                                         
    set sashelp.vcolumn end = z ;                                        
    where libname = "WORK" and memname = "HAVE" ;                        
    length v_list $ 32767 ;                                              
    v_list = catx (" ", v_list, name) ;                                  
    if name = "&amp;amp;v_aft" then v_list = catx (" ", v_list, "&amp;amp;v_ins") ;      
  end ;                                                                  
  call symputx ("v_list", v_list) ;                                      
run ;                                                                    
                                                                         
data want ;                                                              
  retain &amp;amp;v_list ;                                                       
  length &amp;amp;v_ins &amp;amp;v_len ;                                                 
  call missing (&amp;amp;v_ins) ;                                                
  set have ;                                                             
run ;                                                                    &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Now if you look at the data set WANT, you'll see the variable D right between C and E. The piece producing V_LIST may look rather maladroit, yet in reality it exacts little overhead since it only reads the metadata.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Paul D.&lt;/P&gt;</description>
    <pubDate>Tue, 07 Aug 2018 04:12:32 GMT</pubDate>
    <dc:creator>hashman</dc:creator>
    <dc:date>2018-08-07T04:12:32Z</dc:date>
    <item>
      <title>COLUMN INSERT BETWEEN TO VARIABLE COLUMNS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/COLUMN-INSERT-BETWEEN-TO-VARIABLE-COLUMNS/m-p/484587#M125815</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 213px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/22281i52A54131D4C0B466/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;so with out writing all columns names how can I insert a column only by naming the column to the right and left?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Aug 2018 01:44:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/COLUMN-INSERT-BETWEEN-TO-VARIABLE-COLUMNS/m-p/484587#M125815</guid>
      <dc:creator>dane77221</dc:creator>
      <dc:date>2018-08-07T01:44:45Z</dc:date>
    </item>
    <item>
      <title>Re: COLUMN INSERT BETWEEN TO VARIABLE COLUMNS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/COLUMN-INSERT-BETWEEN-TO-VARIABLE-COLUMNS/m-p/484589#M125816</link>
      <description>&lt;P&gt;Consider you have the data as below , this is a untested code but hopefully should work&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input alphabets $;
cards;
A
B
C
E
F
G
H
;

create a dummy dataset;
data dum;
input alphabets $;
cards;
A
B
C
D
E
F
G
H
;

data all;
merge have dum;
by alphabets ;
run;

proc transpose data=all;
var alphabets;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Aug 2018 01:57:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/COLUMN-INSERT-BETWEEN-TO-VARIABLE-COLUMNS/m-p/484589#M125816</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2018-08-07T01:57:10Z</dc:date>
    </item>
    <item>
      <title>Re: COLUMN INSERT BETWEEN TO VARIABLE COLUMNS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/COLUMN-INSERT-BETWEEN-TO-VARIABLE-COLUMNS/m-p/484591#M125817</link>
      <description>&lt;P&gt;thank you for you help but the issue is there are two many columns to list out all column names.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Aug 2018 02:11:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/COLUMN-INSERT-BETWEEN-TO-VARIABLE-COLUMNS/m-p/484591#M125817</guid>
      <dc:creator>dane77221</dc:creator>
      <dc:date>2018-08-07T02:11:07Z</dc:date>
    </item>
    <item>
      <title>Re: COLUMN INSERT BETWEEN TO VARIABLE COLUMNS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/COLUMN-INSERT-BETWEEN-TO-VARIABLE-COLUMNS/m-p/484595#M125818</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WANT;
&amp;nbsp; if 0 then set HAVE(keep=A--C);
&amp;nbsp; length D 8;
&amp;nbsp; if 0 then set HAVE(keep=E--G);
  more code..  set HAVE;  more code...
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>Tue, 07 Aug 2018 02:23:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/COLUMN-INSERT-BETWEEN-TO-VARIABLE-COLUMNS/m-p/484595#M125818</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-08-07T02:23:31Z</dc:date>
    </item>
    <item>
      <title>Re: COLUMN INSERT BETWEEN TO VARIABLE COLUMNS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/COLUMN-INSERT-BETWEEN-TO-VARIABLE-COLUMNS/m-p/484608#M125822</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/224531"&gt;@dane77221&lt;/a&gt;:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I like the elegance of the solution&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp;has offered. But since you said you want to specify nothing but the names of the surrounding variables, I'd offer one where you need to name only the variable &lt;EM&gt;after&lt;/EM&gt; which you want the insertion (and, of course, necessarily the name and other attributes of the variable you want to insert). Thus, if you originally have a data set:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;                                             
  retain A "A" B "BB" C "CCC" E "EEEEE" F "FFFFFF" G 1 ;
  do G = 1 to 10 ;                                      
    output ;                                            
  end ;                                                 
run ;                                                   &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;and want to insert a variable D after variable C, you could code as follows:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let v_aft =  C ;                                                        
%let v_ins =  D ;                                                        
%let v_len = $4 ; * if you want D as numeric, just code 8 instead of $4 ;
                                                                         
data _null_ ;                                                            
  do until (z) ;                                                         
    set sashelp.vcolumn end = z ;                                        
    where libname = "WORK" and memname = "HAVE" ;                        
    length v_list $ 32767 ;                                              
    v_list = catx (" ", v_list, name) ;                                  
    if name = "&amp;amp;v_aft" then v_list = catx (" ", v_list, "&amp;amp;v_ins") ;      
  end ;                                                                  
  call symputx ("v_list", v_list) ;                                      
run ;                                                                    
                                                                         
data want ;                                                              
  retain &amp;amp;v_list ;                                                       
  length &amp;amp;v_ins &amp;amp;v_len ;                                                 
  call missing (&amp;amp;v_ins) ;                                                
  set have ;                                                             
run ;                                                                    &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Now if you look at the data set WANT, you'll see the variable D right between C and E. The piece producing V_LIST may look rather maladroit, yet in reality it exacts little overhead since it only reads the metadata.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Paul D.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Aug 2018 04:12:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/COLUMN-INSERT-BETWEEN-TO-VARIABLE-COLUMNS/m-p/484608#M125822</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2018-08-07T04:12:32Z</dc:date>
    </item>
  </channel>
</rss>

