<?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 to - Replace/Change Variables Values Dynamically in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-Replace-Change-Variables-Values-Dynamically/m-p/286701#M58852</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13549"&gt;@Cynthia_sas﻿&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes, this is what I want -&amp;gt;&lt;SPAN&gt;&amp;nbsp;"Are you saying that no matter what the value of the internal order variable is, if the value of Preffix is 'Dev' then the order changes to 1 and if the value is 'Rec', then that is always the Last order???"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Actually, there is no logic, these values into the "Have" data set is an input data. Some person will fill the values then I will order depending on "DEV" and "REC". "DEV" should be first and "REC" should be last.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 24 Jul 2016 19:16:23 GMT</pubDate>
    <dc:creator>turcay</dc:creator>
    <dc:date>2016-07-24T19:16:23Z</dc:date>
    <item>
      <title>How to - Replace/Change Variables Values Dynamically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Replace-Change-Variables-Values-Dynamically/m-p/286663#M58832</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to replace/change variables values depending on their orders.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a sample code as below, I want to replace Order variable values with each other but depending on "DEV" and "REC" values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you can examine my followimg sample, you can understand what I try to do.&amp;nbsp;I would also like to point out that "Have" data set can include more than for rows. So Order of "REC" value should replace with latest value of "Order"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can somebody help me, please?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Have;
Length DataSet $ 32 Preffix $ 32 Order 8;
Infile Datalines Missover;
Input DataSet Preffix Order;
Datalines;
Have Mdl 1
Want Dev 2
Last Rec 3
Desired Val 4
;
Run;

Data Want;
Set Have;
If Upcase(Preffix)="DEV" Then Order=1;
If Upcase(Preffix)="REC" Then Order=4;
/*There can be more than four data set
so I need to assign this value to latest "Order" value*/
/*If Upcase(Preffix)="DEV" Then Do;*/
/*Order=TranWrd(Order,2,1);*/
/*Order=TranWrd(Order,1,2);*/
/*End;*/
/*If Upcase(Preffix)="REC" Then Do;*/
/*Order=TranWrd(Order,3,4);*/
/*Order=TranWrd(Order,4,3);*/
/*End;*/
Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Desired -&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/4199i5702A3A47CE2CCE4/image-size/original?v=v2&amp;amp;px=-1" border="0" alt="Desired.png" title="Desired.png" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What if "Have" data set will be as below, how can I replace order of "REC" &amp;nbsp;with latest row?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Have;
Length DataSet $ 32 Preffix $ 32 Order 8;
Infile Datalines Missover;
Input DataSet Preffix Order;
Datalines;
Have Mdl 1
Want Dev 2
Last Rec 3
Want2 Val2 4
Desired Val 5
Have2 Mdl2 6
;
Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Sun, 24 Jul 2016 14:54:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Replace-Change-Variables-Values-Dynamically/m-p/286663#M58832</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2016-07-24T14:54:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Replace/Change Variables Values Dynamically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Replace-Change-Variables-Values-Dynamically/m-p/286666#M58833</link>
      <description>Hi, I don't understand what you want. Are you saying that no matter what the value of the internal order variable is, if the value of Preffix is 'Dev' then the order changes to 1 and if the value is 'Rec', then that is always the Last order??? What about the ones between the first and last?  If you make this modification to your posted code, creating a variable called origOrder, so we can see what the order value was originally, I do not understand the logic for the desired output your show in your screen shot...for example  "Have" is originally order=1, what is the logic that makes it order=2 and "Desired" is originally order=4, what is the logic that makes it order=3. Noone can help you with the second question until you explain the logic of the what you first showed. &lt;BR /&gt; &lt;BR /&gt;Here is the modified version of your program. Can you explain the logic behind how the other rows get renumbered???&lt;BR /&gt;&lt;BR /&gt;cynthia&lt;BR /&gt;&lt;BR /&gt;**the code;&lt;BR /&gt;&lt;BR /&gt;Data Have;&lt;BR /&gt;Length DataSet $ 32 Preffix $ 32 origOrder 8;&lt;BR /&gt;Infile Datalines Missover;&lt;BR /&gt;Input DataSet Preffix origOrder;&lt;BR /&gt;Datalines;&lt;BR /&gt;Have Mdl 1&lt;BR /&gt;Want Dev 2&lt;BR /&gt;Last Rec 3&lt;BR /&gt;Desired Val 4&lt;BR /&gt;;&lt;BR /&gt;Run;&lt;BR /&gt;&lt;BR /&gt;title;&lt;BR /&gt;Data Want;&lt;BR /&gt;Set Have;&lt;BR /&gt;If Upcase(Preffix)="DEV" Then Order=1;&lt;BR /&gt;else If Upcase(Preffix)="REC" Then Order=4;&lt;BR /&gt;else order=.;&lt;BR /&gt;Run;&lt;BR /&gt;&lt;BR /&gt;proc print data=want;&lt;BR /&gt;run;&lt;BR /&gt;title;&lt;BR /&gt;</description>
      <pubDate>Sun, 24 Jul 2016 15:28:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Replace-Change-Variables-Values-Dynamically/m-p/286666#M58833</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2016-07-24T15:28:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Replace/Change Variables Values Dynamically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Replace-Change-Variables-Values-Dynamically/m-p/286671#M58837</link>
      <description>&lt;P&gt;It's a mistake to try to do this in one step. &amp;nbsp;Just assign some extreme values:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;if upcase(preffix)='DEV' then order=-5;&lt;/P&gt;
&lt;P&gt;else if upcase(preffix)='REC' then order=99999;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=want;&lt;/P&gt;
&lt;P&gt;by order;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set want;&lt;/P&gt;
&lt;P&gt;order = _n_;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The data set is small, so take advantage of that. &amp;nbsp;Use multiple easy programming steps.&lt;/P&gt;</description>
      <pubDate>Sun, 24 Jul 2016 15:55:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Replace-Change-Variables-Values-Dynamically/m-p/286671#M58837</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-07-24T15:55:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Replace/Change Variables Values Dynamically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Replace-Change-Variables-Values-Dynamically/m-p/286676#M58839</link>
      <description>&lt;P&gt;Here is an Array way.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I use array to keep the Observation Number(Record ID). Then I exchange the positions of Record IDs depending on 'Dev' and 'Rec'.&lt;/P&gt;&lt;P&gt;But the data set is used 3 times which I think is a limitation unless proved otherwise.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   if _N_ = 1 then do;
      array k[7] _temporary_;
      do i = 1 by 1 until(eof);
         set have end = eof;
         k[Order] = i;
      end;
   end;
   do i = 1 by 1 until(last);
      set have end = last;
      if upcase(Preffix) = 'DEV' then do;
         k[dim(k)] = k[1];
         k[1] = i;
         k[i] = k[dim(k)];
      end;
      if upcase(Preffix) = 'REC' then do;
         k[dim(k)] = k[4];
         k[4] = i;
         k[i] = k[dim(k)];
      end;
   end;
   if eof;
      do i = 1 to dim(k) - 1;
         pt = k[i];
         set have point = pt;
         Order = i;
         output;
      end;
drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;For 6 observations, the array is sized to 7. The 7th cell is used for exchanges. The first do-loop assigns the RID to the array cells. The second do-loop exchanges the RIDs. The third do-loop uses POINT= option to get the desired observation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We can avoid the 3 passes over the data set by holding other two variables in two separate arrays and do the exchanges on them whenever there is exchange in ORDER.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyway this fun with Array.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 24 Jul 2016 17:49:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Replace-Change-Variables-Values-Dynamically/m-p/286676#M58839</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2016-07-24T17:49:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Replace/Change Variables Values Dynamically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Replace-Change-Variables-Values-Dynamically/m-p/286701#M58852</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13549"&gt;@Cynthia_sas﻿&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes, this is what I want -&amp;gt;&lt;SPAN&gt;&amp;nbsp;"Are you saying that no matter what the value of the internal order variable is, if the value of Preffix is 'Dev' then the order changes to 1 and if the value is 'Rec', then that is always the Last order???"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Actually, there is no logic, these values into the "Have" data set is an input data. Some person will fill the values then I will order depending on "DEV" and "REC". "DEV" should be first and "REC" should be last.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 24 Jul 2016 19:16:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Replace-Change-Variables-Values-Dynamically/m-p/286701#M58852</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2016-07-24T19:16:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Replace/Change Variables Values Dynamically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Replace-Change-Variables-Values-Dynamically/m-p/286702#M58853</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding﻿&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your reply gives me what I want, Thank you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To decrease data step count, if I write Proc Sql as below, Is it affect the performance positive or negative?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also is it possible for me to add your Order=_N_ step into the PROC SQL step?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc Sql;
Create Table Want As
Select Dataset
,Preffix
,Case
When Upcase(Preffix)="DEV" Then -5
WHEN Upcase(Preffix)="REC" Then 99999
Else Order
End AS Order
From Have
Order By Order;
Quit;

 
Data Want2;
Set Want;
Order=_N_;
Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Sun, 24 Jul 2016 19:30:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Replace-Change-Variables-Values-Dynamically/m-p/286702#M58853</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2016-07-24T19:30:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Replace/Change Variables Values Dynamically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Replace-Change-Variables-Values-Dynamically/m-p/286704#M58855</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/17813"&gt;@KachiM﻿&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you very much for your detailed information. But I did not understand what should I do, if there are six observation?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In your method, I need to know count&amp;nbsp;of observations number, is it &amp;nbsp;possible to perform your method without knowing the observation count. Because the observation count can change.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Sun, 24 Jul 2016 19:38:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Replace-Change-Variables-Values-Dynamically/m-p/286704#M58855</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2016-07-24T19:38:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Replace/Change Variables Values Dynamically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Replace-Change-Variables-Values-Dynamically/m-p/286707#M58858</link>
      <description>&lt;P&gt;A small program get it.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
   if 0 then set have nobs = n;
   call symputx('nplusone', n + 1);
stop;
run;
%put &amp;amp;nplusone;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Place &amp;amp;nplusone wherever 7 appears.&lt;/P&gt;</description>
      <pubDate>Sun, 24 Jul 2016 19:58:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Replace-Change-Variables-Values-Dynamically/m-p/286707#M58858</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2016-07-24T19:58:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Replace/Change Variables Values Dynamically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Replace-Change-Variables-Values-Dynamically/m-p/286708#M58859</link>
      <description>&lt;P&gt;Thank you very much,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I change data set as below and replace 7 with&amp;nbsp;&amp;amp;nplusone. the result doesn't become what I &amp;nbsp;want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Have;
Length DataSet $ 32 Preffix $ 32 Order 8;
Infile Datalines Missover;
Input DataSet Preffix Order;
Datalines;
Have Mdl 1
Want Dev 2
Last Rec 3
Want2 Val2 4
Desired Val 5
Have2 Mdl2 6
;
Run;

data _null_;
   if 0 then set have nobs = n;
   call symputx('nplusone', n + 1);
stop;
run;
%put &amp;amp;nplusone;

data want;
   if _N_ = 1 then do;
      array k[&amp;amp;nplusone.] _temporary_;
      do i = 1 by 1 until(eof);
         set have end = eof;
         k[Order] = i;
      end;
   end;
   do i = 1 by 1 until(last);
      set have end = last;
      if upcase(Preffix) = 'DEV' then do;
         k[dim(k)] = k[1];
         k[1] = i;
         k[i] = k[dim(k)];
      end;
      if upcase(Preffix) = 'REC' then do;
         k[dim(k)] = k[4];
         k[4] = i;
         k[i] = k[dim(k)];
      end;
   end;
   if eof;
      do i = 1 to dim(k) - 1;
         pt = k[i];
         set have point = pt;
         Order = i;
         output;
      end;
drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Sun, 24 Jul 2016 21:16:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Replace-Change-Variables-Values-Dynamically/m-p/286708#M58859</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2016-07-24T21:16:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Replace/Change Variables Values Dynamically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Replace-Change-Variables-Values-Dynamically/m-p/286717#M58865</link>
      <description>&lt;P&gt;This is the output I am getting. Is this OK or not?&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; Obs    DataSet    Preffix    Order

  1     Want        Dev         1
  2     Have        Mdl         2
  3     Want2       Val2        3
  4     Last        Rec         4
  5     Desired     Val         5
  6     Have2       Mdl2        6&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 24 Jul 2016 22:57:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Replace-Change-Variables-Values-Dynamically/m-p/286717#M58865</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2016-07-24T22:57:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Replace/Change Variables Values Dynamically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Replace-Change-Variables-Values-Dynamically/m-p/286722#M58867</link>
      <description>&lt;P&gt;Actually, it should be the following table;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/4201i61991E28D2FCC455/image-size/original?v=v2&amp;amp;px=-1" border="0" alt="Desired.png" title="Desired.png" /&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 24 Jul 2016 23:19:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Replace-Change-Variables-Values-Dynamically/m-p/286722#M58867</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2016-07-24T23:19:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Replace/Change Variables Values Dynamically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Replace-Change-Variables-Values-Dynamically/m-p/286723#M58868</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding﻿&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;According to your response, I would like to ask one more question to you. What if I don't have Order variable in the data set, can I still order the table the way&amp;nbsp;I want?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What if have following table;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Have;
Length DataSet $ 32 Preffix $ 32;
Infile Datalines Missover;
Input DataSet Preffix ;
Datalines;
Have Mdl
Want Dev
Last Rec
Want2 Val
Desired Val
Have2 Mdl2
;
Run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 24 Jul 2016 23:22:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Replace-Change-Variables-Values-Dynamically/m-p/286723#M58868</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2016-07-24T23:22:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Replace/Change Variables Values Dynamically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Replace-Change-Variables-Values-Dynamically/m-p/286727#M58870</link>
      <description>&lt;P&gt;Yes.&lt;/P&gt;&lt;P&gt;Replace Order by _N_ in the first do-loop whic is i here.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Edited.....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;      do i &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;1&lt;/SPAN&gt; &lt;SPAN class="token statement"&gt;by&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;1&lt;/SPAN&gt; until&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;eof&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
         &lt;SPAN class="token keyword"&gt;set&lt;/SPAN&gt; have end &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; eof&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
         k&lt;SPAN class="token punctuation"&gt;[&lt;SPAN style="line-height: 20px;"&gt;i&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;]&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; i&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
      end&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jul 2016 00:11:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Replace-Change-Variables-Values-Dynamically/m-p/286727#M58870</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2016-07-25T00:11:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Replace/Change Variables Values Dynamically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Replace-Change-Variables-Values-Dynamically/m-p/286728#M58871</link>
      <description>&lt;P&gt;Hi:&lt;BR /&gt; Pardon my confusion. &lt;BR /&gt;&lt;BR /&gt; Why did you post data with an ORDER and go on and on about needing a new ORDER variable if your data does not have an ORDER variable in the first place?&lt;BR /&gt;&lt;BR /&gt; Of course, when you read the data, you could make the original order variable by assigning _N_ to the ORDER variable and then go through the rest of the steps as previously shown by other participants.&lt;BR /&gt; &lt;BR /&gt;cynthia&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jul 2016 00:08:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Replace-Change-Variables-Values-Dynamically/m-p/286728#M58871</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2016-07-25T00:08:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Replace/Change Variables Values Dynamically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Replace-Change-Variables-Values-Dynamically/m-p/286734#M58876</link>
      <description>&lt;P&gt;Yes, assuming your SQL code is working you can cut out a step that way. &amp;nbsp;But these data sets are small. &amp;nbsp;The most efficient method doesn't depend on the number of steps. &amp;nbsp;Use whatever you would find easy to understand when you are reviewing the program a year from now.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jul 2016 00:43:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Replace-Change-Variables-Values-Dynamically/m-p/286734#M58876</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-07-25T00:43:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Replace/Change Variables Values Dynamically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Replace-Change-Variables-Values-Dynamically/m-p/286744#M58885</link>
      <description>&lt;PRE&gt;


Data Have;
Length DataSet $ 32 Preffix $ 32 Order 8;
Infile Datalines Missover;
Input DataSet Preffix Order;
Datalines;
Have Mdl 1
Want Dev 2
Last Rec 3
Want2 Val2 4
Desired Val 5
Have2 Mdl2 6
;
Run;

data want; 
 if _n_=1 then do;
  if 0 then set have(rename=(Order=_Order Preffix=_Preffix));
  declare hash h(dataset:'have(rename=(Order=_Order Preffix=_Preffix) where=(_Preffix in ("Dev" "Rec")))');
  h.definekey('_Preffix');
  h.definedata('_Order');
  h.definedone();
 end;
set have nobs=nobs end=last;
if _n_=1 then do;
 _Preffix='Dev'; h.find(); Order=_Order;
end;
if Preffix='Dev' then Order=1;
if Preffix='Rec' then Order=nobs;
if last then do;
 _Preffix='Rec'; h.find(); Order=_Order;
end;
drop _:;
run;


&lt;/PRE&gt;</description>
      <pubDate>Mon, 25 Jul 2016 02:29:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Replace-Change-Variables-Values-Dynamically/m-p/286744#M58885</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-07-25T02:29:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Replace/Change Variables Values Dynamically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Replace-Change-Variables-Values-Dynamically/m-p/286853#M58926</link>
      <description>&lt;P&gt;In previous post input data set had 3 passes. In the following program, it needs one pass to store the Record IDs in an array(K) and another pass to directly to go to the required record for output. As records are processed the Preffix variable is checked for 'DEV' and 'REC' and if they found, their RID is saved in another array(P). Once the RIDs are in the array(K), comparing with (P), exchanges are made. Finally the array(K) has the required order of RIDs. The final do-loop uses cell values of K to directly hit the record for the output.&amp;nbsp;&lt;/P&gt;&lt;P&gt;A small modification to the data set is made. No need for the ORDER variable in the input data set. Here is everything:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have;
Length DataSet $ 32 Preffix $ 32;
Infile Datalines Missover;
Input DataSet Preffix;
datalines;
Have Mdl
Want2 Val2
Desired Val
Have2 Mdl2
have3 Mdl3
want2 Val3
have4 Mdl4
have5 Mdl5
Last Rec
Want Dev
;
run;

data _null_;
   if 0 then set have nobs = n;
   call symputx('nplusone', n + 1);
stop;
run;
%put &amp;amp;nplusone;

data want;
   if _N_ = 1 then do;
      array k[&amp;amp;nplusone] _temporary_;
      array p[&amp;amp;nplusone] _temporary_;
      do i = 1 by 1 until(eof);
         set have end = eof;
         k[i] = i;
         if upcase(Preffix) = 'DEV' then p[i] = 1;
         else if upcase(Preffix) = 'REC' then p[i] = 4;
      end;
      do i = 1 to dim(k) - 1;
         if not missing(p[i]) then do;
            k[dim(k)] = p[i];
            k[p[i]] = i;
            k[i] = k[dim(k)];
         end;
      end;
   end;
   if eof;
      do i = 1 to dim(k) - 1;
         pt = k[i];
         set have point = pt;
         Order = i;
         output;
      end;
      stop;
drop i;
run;

proc print data = want;
run;


  DataSet    Preffix    Order

  Want        Dev          1
  Want2       Val2         2
  Desired     Val          3
  Last        Rec          4
  have3       Mdl3         5
  want2       Val3         6
  have4       Mdl4         7
  have5       Mdl5         8
  Have2       Mdl2         9
  Have        Mdl         10&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 25 Jul 2016 13:21:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Replace-Change-Variables-Values-Dynamically/m-p/286853#M58926</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2016-07-25T13:21:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Replace/Change Variables Values Dynamically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Replace-Change-Variables-Values-Dynamically/m-p/286925#M58953</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13549"&gt;@Cynthia_sas﻿&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The data which I wrote, is an input table so it can change not because of me. That is the reason why also I want to ask what if Order variable is not contained, question.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The method which I did as below. I think you also suggested &amp;nbsp;me the sample method. If I understood incorrect, I'm sorry &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&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 Pre_Want;
Order=_N_;
Run;

Proc Sql;
Create Table Want As
Select Dataset
,Preffix
,Case
When Upcase(Preffix)="DEV" Then -5
WHEN Upcase(Preffix)="REC" Then 99999
Else Order
End AS Order
From Have
Order By Order;
Quit;

Data Want2;
Set Want;
Order=_N_;
Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jul 2016 16:55:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Replace-Change-Variables-Values-Dynamically/m-p/286925#M58953</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2016-07-25T16:55:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Replace/Change Variables Values Dynamically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Replace-Change-Variables-Values-Dynamically/m-p/286949#M58960</link>
      <description>Hi:&lt;BR /&gt;  Yes, I think you're correct. Ksharp has also provided a Hash Table approach. As a check on the level of difficulty, we teach Hash Tables in Programming 3, so if you have a simple method that works for you, especially since you have so few rows, that is probably the better approach. Especially if you need to turn this code over to folks who are less experienced at using SAS than you are. Although HASH tables are very powerful, I think they may be too much for what your aim is.&lt;BR /&gt; &lt;BR /&gt;BTW, when you are getting data from someone, you say that "The data ... is an input table so it can change not because of me" -- if you are allowing other folks to change the table they give you, that generally is a sign that the requirements are still in flux and that you are going to be constantly fiddling with/modifying your program to suit the data they send you. If the users (I assume it is users who are sending you the possibly changeable input table) cannot agree on a format for this table you need, then I would recommend getting them to agree on a standard way to send you the data. Otherwise, you will not ever be able to turn anything over for production. &lt;BR /&gt; &lt;BR /&gt;cynthia</description>
      <pubDate>Mon, 25 Jul 2016 17:31:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Replace-Change-Variables-Values-Dynamically/m-p/286949#M58960</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2016-07-25T17:31:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Replace/Change Variables Values Dynamically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Replace-Change-Variables-Values-Dynamically/m-p/287041#M58995</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13549"&gt;@Cynthia_sas﻿&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you so much for your warm approach .Your approach and your reccommendation are much appreciated.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;At this moment, learning Hash is also far from me, it seems difficult but I can guess how powerful Hash code is . I need a time to converge it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;About your second reccomandation you are totally right. This statement is what I'm facing nowadays -&amp;gt;&amp;nbsp;&lt;STRONG&gt;&lt;SPAN&gt;that generally is a sign that the requirements are still in flux and that you are going to be constantly fiddling with/modifying your program to suit the data they send you.&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jul 2016 21:47:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Replace-Change-Variables-Values-Dynamically/m-p/287041#M58995</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2016-07-25T21:47:55Z</dc:date>
    </item>
  </channel>
</rss>

