<?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: change variable names (not so easy) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/change-variable-names-not-so-easy/m-p/549907#M152647</link>
    <description>&lt;P&gt;Thank you so much for your answer and for the time you take.. i really appreciate !&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It seems like it works ! I just have to change the variable names, because that happen :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/28610iBB38C700C4ECB386/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So i rename the variables with this code because i don't have your skill on sas and so i don't understand your data _null_ haha&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want1 ;
set want(rename = (revcniv8 = cniv1 revcniv7 = cniv2 revcniv6 = cniv3 revcniv5 = cniv4 revcniv4 = cniv5 revcniv3 = cniv6 revcniv2 = cniv7 revcniv1 = cniv8));
run ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;After lunch, I am going to look if it works perfectly for the entire data bases and if it is OK, i'm putting your solution as THE solution haha&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Again, thank you very much !!!&lt;/P&gt;</description>
    <pubDate>Wed, 10 Apr 2019 10:38:57 GMT</pubDate>
    <dc:creator>Onizuka</dc:creator>
    <dc:date>2019-04-10T10:38:57Z</dc:date>
    <item>
      <title>change variable names (not so easy)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-variable-names-not-so-easy/m-p/549898#M152643</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The is the third time i'm writting the same topic, i have a bug, my topic remove himself after an edit...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Well, i'm writting it again.....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have 9 variables :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;- &lt;STRONG&gt;level&lt;/STRONG&gt; (which contain a value between 1 and &lt;span class="lia-unicode-emoji" title=":smiling_face_with_sunglasses:"&gt;😎&lt;/span&gt;&lt;/P&gt;&lt;P&gt;- &lt;STRONG&gt;cniv1&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;- &lt;STRONG&gt;cniv2&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;- ...&lt;/P&gt;&lt;P&gt;- &lt;STRONG&gt;cniv8&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to change the order of the codes depend of the level of it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Well, images are more meaningful than words..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;On this first example, i'm taking a level = 5&lt;/P&gt;&lt;P&gt;The first board contain what i have and the second one, what i want :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture1.PNG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/28608i50A3C6CBEE913D3F/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture1.PNG" alt="Capture1.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm putting now a second example taking level = 7&lt;/P&gt;&lt;P&gt;It is the same, the first board = what i have&lt;/P&gt;&lt;P&gt;&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; the second board = what i want&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/28609i364D8AC3559DE883/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for the answers and i'm really sorry for the ones who read the topic for the third time.. I promise to not edit my post anymore..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Good afternoon,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Onizuka&lt;/P&gt;</description>
      <pubDate>Wed, 10 Apr 2019 10:04:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-variable-names-not-so-easy/m-p/549898#M152643</guid>
      <dc:creator>Onizuka</dc:creator>
      <dc:date>2019-04-10T10:04:49Z</dc:date>
    </item>
    <item>
      <title>Re: change variable names (not so easy)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-variable-names-not-so-easy/m-p/549900#M152644</link>
      <description>&lt;P&gt;First, you might want to change the title, as I don't see how this particular problem involves changing variable names. It seems more like you need to re-order the values in these 8 variables CNIV1-CNIV8.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;On this first example, i'm taking a level = 5&lt;/P&gt;
&lt;P&gt;The first board contain what i have and the second one, what i want :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" style="width: 600px;"&gt;&lt;SPAN class="lia-message-image-wrapper lia-message-image-actions-narrow lia-message-image-actions-below"&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture1.PNG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/28608i50A3C6CBEE913D3F/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture1.PNG" alt="Capture1.PNG" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" style="width: 600px;"&gt;I believe you are trying to say that when level is 5, then the value of CNIV5 becomes the value of CNIV1. That seems relatively clear, but why do the other values change positions as well? You need to explain the rules by which the other values have been re-ordered within CNIV2-CNIV8 (I think I understand how CNIV1 is assigned).&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Apr 2019 10:11:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-variable-names-not-so-easy/m-p/549900#M152644</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-04-10T10:11:47Z</dc:date>
    </item>
    <item>
      <title>Re: change variable names (not so easy)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-variable-names-not-so-easy/m-p/549901#M152645</link>
      <description>&lt;P&gt;Try the following program. If you don't need the column names to be maintained, you can drop&lt;/P&gt;
&lt;P&gt;the last data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input level cniv1-cniv8;
cards;
5 1 3 0 2 4 . . .
;
run;

data want;
set have;
array revcniv(*) revcniv8-revcniv1;
array cniv(*) cniv1-cniv8;

j=1;
do i=dim(cniv) to 1 by -1;
    if cniv(i) ne . then do;
        revcniv(j)=cniv(i);
	    j+1;
	end;
end;

drop cniv: i j;
run;

/* Renale columns back to cniv* */
data _NULL_;
    set want;
	length NAME $32.;
	call execute('data want; set want;');
	do while (NAME ne "NAME");
	    call vnext(NAME);
	    if upcase(NAME)=:"REV" then do;
	        call execute(cat('rename ',NAME,"=",substr(NAME,4),";"));
	    end;
	end;
	call execute('run;');
	stop;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 10 Apr 2019 10:12:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-variable-names-not-so-easy/m-p/549901#M152645</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2019-04-10T10:12:18Z</dc:date>
    </item>
    <item>
      <title>Re: change variable names (not so easy)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-variable-names-not-so-easy/m-p/549904#M152646</link>
      <description>&lt;P&gt;Thank you for your answer. You are right, i should have change the title but I confess that I'm afraid to do it for fear that the post will be deleted again...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You understood well my problem, i am a french student and i find it difficult to explain in French, so in English... haha&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I receive data from differents companies which have different hierarchies.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Some companies have 4 level of hierarchy, others 7 or 8 or 3...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When i receive the file, if a compagny have only 4 levels then cniv5 .... cniv8 is empty and the hierarchies are sorted in ascending order. But the ask me to put the hierarchy in descending order.. so the "House" on cniv1..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope it's more clear.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Mateo&lt;/P&gt;</description>
      <pubDate>Wed, 10 Apr 2019 10:24:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-variable-names-not-so-easy/m-p/549904#M152646</guid>
      <dc:creator>Onizuka</dc:creator>
      <dc:date>2019-04-10T10:24:31Z</dc:date>
    </item>
    <item>
      <title>Re: change variable names (not so easy)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-variable-names-not-so-easy/m-p/549907#M152647</link>
      <description>&lt;P&gt;Thank you so much for your answer and for the time you take.. i really appreciate !&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It seems like it works ! I just have to change the variable names, because that happen :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/28610iBB38C700C4ECB386/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So i rename the variables with this code because i don't have your skill on sas and so i don't understand your data _null_ haha&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want1 ;
set want(rename = (revcniv8 = cniv1 revcniv7 = cniv2 revcniv6 = cniv3 revcniv5 = cniv4 revcniv4 = cniv5 revcniv3 = cniv6 revcniv2 = cniv7 revcniv1 = cniv8));
run ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;After lunch, I am going to look if it works perfectly for the entire data bases and if it is OK, i'm putting your solution as THE solution haha&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Again, thank you very much !!!&lt;/P&gt;</description>
      <pubDate>Wed, 10 Apr 2019 10:38:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-variable-names-not-so-easy/m-p/549907#M152647</guid>
      <dc:creator>Onizuka</dc:creator>
      <dc:date>2019-04-10T10:38:57Z</dc:date>
    </item>
    <item>
      <title>Re: change variable names (not so easy)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-variable-names-not-so-easy/m-p/549908#M152648</link>
      <description>&lt;P&gt;As soon as you abandon the disadvantageous wide format, it's all simple:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input level cniv1-cniv8;
datalines;
5 5000 400 600 10 50 . . .
7 5000 30 600 500 5 30 4400 .
;
run;

proc transpose data=have out=trans (where=(col1 ne .));
by level;
var cniv:;
run;

proc sort data=trans;
by level descending _name_;
run;

data want;
set trans;
by level;
retain i;
if first.level
then i = 1;
else i + 1;
_name_ = cats(substr(_name_,1,4),i);
drop i;
run;

proc transpose data=want out=want_wide (drop=_name_);
by level;
var col1;
id _name_;
run;

proc print data=want_wide noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;level    cniv1    cniv2    cniv3    cniv4    cniv5    cniv6    cniv7

  5         50      10      600      400      5000       .         .
  7       4400      30        5      500       600      30      5000
&lt;/PRE&gt;
&lt;P&gt;Note that the always empty cniv8 has been dropped automatically.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But I'd rather stay with the "long" format of dataset wide, as it is much easier to work with.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And&lt;/P&gt;
&lt;P&gt;"&lt;SPAN&gt;Well, images are more meaningful than words."&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;No.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Code is much more meaningful than pictures, see the way I presented your example data in a form that makes it extremely easy for anyone else to recreate the dataset with just a copy/paste and submit. Don't force us to type data off screenshots, instead help us to help you.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Apr 2019 10:40:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-variable-names-not-so-easy/m-p/549908#M152648</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-04-10T10:40:40Z</dc:date>
    </item>
    <item>
      <title>Re: change variable names (not so easy)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-variable-names-not-so-easy/m-p/549911#M152649</link>
      <description>&lt;P&gt;If you define an array:&amp;nbsp;&lt;CODE class=" language-sas"&gt;array cn cniv1-cniv8;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;Does LEVEL mean number of non-null members in the aarray ?&lt;/P&gt;
&lt;P&gt;Are the null members always at the end of the array?&lt;/P&gt;
&lt;P&gt;What you want seems to be reverse order of values.&lt;/P&gt;
&lt;P&gt;that can be done by an auxiliary array:&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 cn cniv1-cniv8;
       array ax  ax1-ax8;
       do i=1 to dim(ax); ax(i)=.; end;

      do i=1 to level;
           ax(i) = ax(level +1 -i);
      end;
      do i=1 to level;
          cn(i) = ax(i);
      end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Apr 2019 11:04:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-variable-names-not-so-easy/m-p/549911#M152649</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2019-04-10T11:04:30Z</dc:date>
    </item>
    <item>
      <title>Re: change variable names (not so easy)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-variable-names-not-so-easy/m-p/549924#M152652</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for you answer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I totally agree with you.&lt;/P&gt;&lt;P&gt;Nevertheless, I confess that I really did not have the slightest idea of ​​how to carry out this program and that's why I did not put codes in the topic ... Moreover, I could not either to express the need that I had. That's why I took the trouble to post 2 screenshots of an example on Excel. Know that if I had a code beginning to propose, I obviously would have posted ..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just for information, i'm not working on 2 lines but 1500 lines with more than 60 variables, i took the solution of Gamotte which works but I will try to adapt your solution to my dataset which contains more than 60 columns.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you again for the answer and for the next time i will try to put some codes, sorry if it disturbes you :X&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Mateo&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Apr 2019 12:15:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-variable-names-not-so-easy/m-p/549924#M152652</guid>
      <dc:creator>Onizuka</dc:creator>
      <dc:date>2019-04-10T12:15:37Z</dc:date>
    </item>
    <item>
      <title>Re: change variable names (not so easy)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-variable-names-not-so-easy/m-p/549925#M152653</link>
      <description>My bad, it is working perfectly, instead of putting "revcniv8-revcniv1" i just put "revcniv1-revcniv8", thank you again !</description>
      <pubDate>Wed, 10 Apr 2019 12:17:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-variable-names-not-so-easy/m-p/549925#M152653</guid>
      <dc:creator>Onizuka</dc:creator>
      <dc:date>2019-04-10T12:17:39Z</dc:date>
    </item>
    <item>
      <title>Re: change variable names (not so easy)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-variable-names-not-so-easy/m-p/549952#M152663</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input level cniv1-cniv8;
cards;
5 5000 400 600 10 50  . . .
7 5000 30 600 500 5 30 4400 .
;
run;

data want;
set have;
array cniv(*) cniv1-cniv8;
array t(8) _temporary_ ;
call missing(of t(*));
j=1;
do i=dim(cniv) to 1 by -1;
    if cniv(i) ne . then do;
        t(j)=cniv(i);
	    j+1;
	end;
end;
call pokelong (peekclong (addrlong(t[1]), 64), addrlong(cniv[1]), 64) ;
drop i j;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 10 Apr 2019 13:43:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-variable-names-not-so-easy/m-p/549952#M152663</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-04-10T13:43:34Z</dc:date>
    </item>
    <item>
      <title>Re: change variable names (not so easy)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-variable-names-not-so-easy/m-p/550009#M152682</link>
      <description>&lt;P&gt;Sequential numbered arrays are a joy as they are easy and contiguous&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input level cniv1-cniv8 ;
cards;
5 5000 400 600 10 50  . . .
7 5000 30 600 500 5 30 4400 .
;
run;



data want;
set have(rename=(cniv1-cniv8=_c1-_c8));
array c(*) cniv1-cniv8;
array cc(*) _c8-_c1;
array _t(8);
call pokelong (peekclong (addrlong(cc[1]), 64), addrlong(_t[1]), 64) ;
_f=whichn(coalesce(of _t(*)),of _t(*));
_k=(8-_f+1)*8;
call pokelong (peekclong (addrlong(_t[_f]),_k ), addrlong(c[1]), 64) ;
drop _:;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Apr 2019 16:43:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-variable-names-not-so-easy/m-p/550009#M152682</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-04-10T16:43:49Z</dc:date>
    </item>
    <item>
      <title>Re: change variable names (not so easy)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-variable-names-not-so-easy/m-p/550134#M152735</link>
      <description>&lt;P&gt;Hello novinosrin, thank you for the answer and for your time ! The programm you made is not working with my datas, i think that the reason is that my variables cniv1 - cniv8 are formatted as characters and not numbers.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Onizuka&lt;/P&gt;</description>
      <pubDate>Thu, 11 Apr 2019 06:59:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-variable-names-not-so-easy/m-p/550134#M152735</guid>
      <dc:creator>Onizuka</dc:creator>
      <dc:date>2019-04-11T06:59:43Z</dc:date>
    </item>
    <item>
      <title>Re: change variable names (not so easy)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-variable-names-not-so-easy/m-p/550142#M152740</link>
      <description>&lt;P&gt;Imagine I have an input like this :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have ;
  input LEVEL CNIV1 CNIV2 CNIV3 CNIV4 CNIV5 CNIV6 CNIV7 CNIV8 ;
cards;
5 5000 30 600 500 5 . . .
7 5000 30 600 500 5 30 4400 .
5 1 . 3 . 5 . . .            /* 5 levels but 2 missing values */
run ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;If i want to keep the missing values only if they are between values, is it only possible ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So to have something like this in output :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/28641i2C966DD08213EC3E/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Apr 2019 08:16:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-variable-names-not-so-easy/m-p/550142#M152740</guid>
      <dc:creator>Onizuka</dc:creator>
      <dc:date>2019-04-11T08:16:54Z</dc:date>
    </item>
    <item>
      <title>Re: change variable names (not so easy)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-variable-names-not-so-easy/m-p/550146#M152744</link>
      <description>&lt;P&gt;Then we need to add a little trickery to my code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have ;
  input LEVEL CNIV1 CNIV2 CNIV3 CNIV4 CNIV5 CNIV6 CNIV7 CNIV8 ;
cards;
5 5000 30 600 500 5 . . .
7 5000 30 600 500 5 30 4400 .
5 1 . 3 . 5 . . . 
;
run;

/* Since level has a different meaning than I originally thought, we need to create our own group column */

data have1;
set have;
group = _n_;
run;

proc transpose data=have1 out=trans;
by group;
var cniv:;
run;

proc sort data=trans;
by group descending _name_;
run;

data want;
set trans;
by group;
retain i flag;
if first.group
then do;
  i = 0;
  flag = 0;
end;
if col1 ne . then flag = 1;
if flag;
i + 1;
_name_ = cats(substr(_name_,1,4),i);
drop i;
run;

proc transpose data=want out=want_wide1 (drop=_name_);
by group;
var col1;
id _name_;
run;

data want_wide;
if _n_ = 0 then set have; /* this restores all columns, including cniv8 */
merge
  have1 (keep=group level) /* this gets us "level" back */
  want_wide1
;
by group;
drop group;
run;

proc print data=want_wide noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;LEVEL    CNIV1    CNIV2    CNIV3    CNIV4    CNIV5    CNIV6    CNIV7    CNIV8

  5          5     500      600       30      5000       .         .      .  
  7       4400      30        5      500       600      30      5000      .  
  5          5       .        3        .         1       .         .      .  
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Apr 2019 08:38:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-variable-names-not-so-easy/m-p/550146#M152744</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-04-11T08:38:13Z</dc:date>
    </item>
    <item>
      <title>Re: change variable names (not so easy)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-variable-names-not-so-easy/m-p/550204#M152750</link>
      <description>&lt;P&gt;Hello Kurt,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for the answer !&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem is that when I generalize the programm to all my data, all variables are empty except cniv1 - cniv8 and level... (in total, counting cniv et level variables, I have 83 variables so I have 74 variables empty ^^)&lt;/P&gt;</description>
      <pubDate>Fri, 12 Apr 2019 08:09:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-variable-names-not-so-easy/m-p/550204#M152750</guid>
      <dc:creator>Onizuka</dc:creator>
      <dc:date>2019-04-12T08:09:39Z</dc:date>
    </item>
    <item>
      <title>Re: change variable names (not so easy)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-variable-names-not-so-easy/m-p/550509#M152853</link>
      <description>&lt;P&gt;I permit me to up the topic !&lt;/P&gt;</description>
      <pubDate>Fri, 12 Apr 2019 06:57:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-variable-names-not-so-easy/m-p/550509#M152853</guid>
      <dc:creator>Onizuka</dc:creator>
      <dc:date>2019-04-12T06:57:56Z</dc:date>
    </item>
    <item>
      <title>Re: change variable names (not so easy)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-variable-names-not-so-easy/m-p/550514#M152856</link>
      <description>&lt;P&gt;This step&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want_wide;
if _n_ = 0 then set have; /* this restores all columns, including cniv8 */
merge
  have1 (keep=group level) /* this gets us "level" back */
  want_wide1
;
by group;
drop group;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is designed to get all the columns back that are not involved in the double transpose process.&lt;/P&gt;
&lt;P&gt;If you slightly change it&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want_wide;
if _n_ = 0 then set have; /* this restores all columns, including cniv8 */
merge
  have1 (drop=cniv1-cniv8)
  want_wide1
;
by group;
drop group;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;it should do the trick.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Apr 2019 07:18:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-variable-names-not-so-easy/m-p/550514#M152856</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-04-12T07:18:03Z</dc:date>
    </item>
    <item>
      <title>Re: change variable names (not so easy)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-variable-names-not-so-easy/m-p/550523#M152858</link>
      <description>&lt;P&gt;Hello Kurt,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for the answer. The first time I run the codes it doesn't inverse the cniv's variables. I try it again and it seems to work. I am going to add some missing values on my real table "have" to confirm if it work really !&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I come back after to put as solution, thank you for you time, really appreciate your help (and of everyone)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;EDIT : &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt; If you have the time, could you explain the programm you made ? Because I don't understand very well what is done (well, i know that it do what i want but i don't understand every step)..&lt;/P&gt;&lt;P&gt;More preciselly I don't understand this :&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set trans;
by group;
retain i flag;
if first.group
then do;
  i = 0;
  flag = 0;
end;
if col1 ne . then flag = 1;
if flag;
i + 1;
_name_ = cats(substr(_name_,1,4),i);
drop i;
run;

proc transpose data=want out=want_wide1 (drop=_name_);
by group;
var col1;
id _name_;
run;

data want_wide;
if _n_ = 0 then set cim_hierarchie; /* this restores all columns, including cniv8 */
merge
  have1 (drop=cniv1-cniv8)
  want_wide1
;
by group;
drop group;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thank you again !&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Onizuka&lt;/P&gt;</description>
      <pubDate>Fri, 12 Apr 2019 08:10:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-variable-names-not-so-easy/m-p/550523#M152858</guid>
      <dc:creator>Onizuka</dc:creator>
      <dc:date>2019-04-12T08:10:13Z</dc:date>
    </item>
    <item>
      <title>Re: change variable names (not so easy)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-variable-names-not-so-easy/m-p/550541#M152866</link>
      <description>&lt;P&gt;I have added to additional columns to illustrate how they are "brought back", and added comments:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
input LEVEL CNIV1 CNIV2 CNIV3 CNIV4 CNIV5 CNIV6 CNIV7 CNIV8 x1 x2;
cards;
5 5000 30 600 500 5 . . . 1 1
7 5000 30 600 500 5 30 4400 . 2 2
5 1 . 3 . 5 . . . 3 3
;
run;

/* add an artificial "group" that identifies each single observation */
data have1;
set have;
group = _n_;
run;

/* transpose to long data format */
proc transpose data=have1 out=trans;
by group;
var cniv:;
run;

/* reverse the order */
proc sort data=trans;
by group descending _name_;
run;

/* create new order */
data want;
set trans;
by group;
retain i flag;
if first.group
then do;
  i = 0;
  flag = 0; /* flag will be "false" as long as the "initial" missing values are encountered */
end;
if col1 ne . then flag = 1; /* start processing only after the first non-missing value is encountered */
/* from now on, missing values will not be skipped */
if flag; /* subsetting if */
/* only now, we increment and create the new future column name */
i + 1;
_name_ = cats(substr(_name_,1,4),i);
drop i flag;
run;

/* at this point, you could keep this dataset, and join it with have1 by group
   everytime you need the other values */

/* transpose back to wide format */
proc transpose data=want out=want_wide1 (drop=_name_);
by group;
var col1;
id _name_;
run;

/* get the non-transposed columns back */
data want_wide;
if _n_ = 0 then set have; /* this restores all columns in order, including cnivX that were always missing */
merge
  have1 (drop=cniv:) /* don't bring in the original values of the transposed columns */
  want_wide1
;
by group;
drop group;
run;

proc print data=have noobs;
run;

proc print data=want_wide noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt;LEVEL    CNIV1    CNIV2    CNIV3    CNIV4    CNIV5    CNIV6    CNIV7    CNIV8    x1    x2

  5       5000      30      600      500       5         .         .      .       1     1
  7       5000      30      600      500       5        30      4400      .       2     2
  5          1       .        3        .       5         .         .      .       3     3

LEVEL    CNIV1    CNIV2    CNIV3    CNIV4    CNIV5    CNIV6    CNIV7    CNIV8    x1    x2

  5          5     500      600       30      5000       .         .      .       1     1
  7       4400      30        5      500       600      30      5000      .       2     2
  5          5       .        3        .         1       .         .      .       3     3
&lt;/PRE&gt;</description>
      <pubDate>Fri, 12 Apr 2019 08:24:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-variable-names-not-so-easy/m-p/550541#M152866</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-04-12T08:24:29Z</dc:date>
    </item>
    <item>
      <title>Re: change variable names (not so easy)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-variable-names-not-so-easy/m-p/550545#M152867</link>
      <description>&lt;P&gt;Thank you VERY MUCH for all these precious explanations and for adding an additional example (x1 and x2) I really appreciated it !!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I understood everything !Seriously, thank you very much again !&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Have a nice day !&lt;/P&gt;</description>
      <pubDate>Fri, 12 Apr 2019 08:43:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-variable-names-not-so-easy/m-p/550545#M152867</guid>
      <dc:creator>Onizuka</dc:creator>
      <dc:date>2019-04-12T08:43:28Z</dc:date>
    </item>
  </channel>
</rss>

