<?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: Replace all dataset variables using loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Replace-all-dataset-variables-using-loop/m-p/406849#M99123</link>
    <description>&lt;P&gt;I wouldn't do this in a loop - you can create a macro variable holding the rename string and then execute this with Proc Datasets as in the code below NB correct capitalisation is vital in Proc SQL&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data inputset;
	length dataperiod $5 food 8 house 8 material 8;
	infile datalines dlm=",";
	input dataperiod $ food house material $;
	datalines;
Year1,1,5,8
Year2,8,3,2
Year3,3,2,7
;
run;


DATA outputset;
	set inputset;
	Food = dif(Food);
	House = dif(House);
	Material=dif(Material);
run;

proc sql noprint;
	select cats(name,'=','dif',name)
	into :varlist
	separated by ' '
	from dictionary.columns
	where libname= 'WORK' and memname= 'INPUTSET' and name ne 'dataperiod';
quit;

%put &amp;amp;varlist;

proc datasets lib=work;
modify outputset;
rename &amp;amp;varlist;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 24 Oct 2017 08:51:47 GMT</pubDate>
    <dc:creator>ChrisBrooks</dc:creator>
    <dc:date>2017-10-24T08:51:47Z</dc:date>
    <item>
      <title>Replace all dataset variables using loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-all-dataset-variables-using-loop/m-p/406837#M99115</link>
      <description>&lt;P&gt;&lt;FONT size="2"&gt;Hi,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;I am quite new to SAS programming.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;I have a dataset from which I wish to create a new dataset where the variables and observations are replaced with the &lt;EM&gt;first difference&lt;/EM&gt; of the orginal dataset values,&amp;nbsp;while renaming the variable names. &lt;FONT size="2"&gt;Sample below.&amp;nbsp;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;I wish to do this with ALL variables (I have 20 columns), so I think a do-loop should be managable. Anyone got any suggestions?&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;My current code is hardcoded and doesn't change the variable names:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;DATA outputset;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;set inputset;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;Food = dif(Food);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;House = dif(House);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;Material=dif(Mat&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;....&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;RUN;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT size="2"&gt;INPUT&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;Dataperiod&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Food&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;House&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Material&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;…&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;Year1&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;…&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;Year2&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;9&lt;/TD&gt;&lt;TD&gt;…&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;Year3&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;TD&gt;…&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;…&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;…&lt;/TD&gt;&lt;TD&gt;…&lt;/TD&gt;&lt;TD&gt;…&lt;/TD&gt;&lt;TD&gt;…&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;WANTED OUTPUT&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;The variable names (Food, House etc)&amp;nbsp;have no pattern, but I wish to replace ALL the variable names and observations&amp;nbsp;with the below ones, using a loop.&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;Dataperiod&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;dif(Food)&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;dif(House)&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;dif(Material)&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;…&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;Year1&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;…&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;Year2&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;TD&gt;-2&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;…&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;Year3&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;-5&lt;/TD&gt;&lt;TD&gt;-1&lt;/TD&gt;&lt;TD&gt;-2&lt;/TD&gt;&lt;TD&gt;…&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;…&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;…&lt;/TD&gt;&lt;TD&gt;…&lt;/TD&gt;&lt;TD&gt;…&lt;/TD&gt;&lt;TD&gt;…&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Tue, 24 Oct 2017 08:10:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-all-dataset-variables-using-loop/m-p/406837#M99115</guid>
      <dc:creator>hermina</dc:creator>
      <dc:date>2017-10-24T08:10:40Z</dc:date>
    </item>
    <item>
      <title>Re: Replace all dataset variables using loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-all-dataset-variables-using-loop/m-p/406845#M99120</link>
      <description>&lt;P&gt;This shows one way to do it.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
  input dataperiod $ food	house	material;
datalines;
Year1	1	5	8	
Year2	8	3	8
Year3	3	2	7
;
run;

data want (drop=i);
  set have;
  array v{3} food house material;
  array r{3} diff_food diff_house diff_material;
  do i=1 to 3;
    r{i}=dif(v{i});
  end;
run;
&lt;/PRE&gt;
&lt;P&gt;This shows arrays and looping over arrays.&amp;nbsp; Its the simplest, but if you have lots of variables then it maybe worth considering a transpose approach like below which doesn't require knowing all the variables up front:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc transpose data=have out=inter;
  by dataperiod;
  var _numeric_;
run;
proc sort data=inter;
  by _name_ dataperiod;
run;
data inter;
  set inter;
  by _name_;
  diff=dif(col1);
  if first._name_ then diff=.;
run;
proc sort data=inter;
  by dataperiod _name_;
run;
proc transpose data=inter out=want;
  by dataperiod;
  var diff;
  id _name_;
run;&lt;/PRE&gt;
&lt;P&gt;Note how I put the test data, please do this in future.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Oct 2017 08:41:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-all-dataset-variables-using-loop/m-p/406845#M99120</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-10-24T08:41:07Z</dc:date>
    </item>
    <item>
      <title>Re: Replace all dataset variables using loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-all-dataset-variables-using-loop/m-p/406847#M99121</link>
      <description>&lt;P&gt;Try next code (not tested):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
      food = food - lag(food);
      house = house - lag(house);
      material = material = lag(material);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What do you mean by LOOP?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Loop accross observations is implicit.&lt;/P&gt;
&lt;P&gt;Loop accross all variables need more preparing code:&lt;/P&gt;
&lt;P&gt;- are there many variables?&lt;/P&gt;
&lt;P&gt;- shall the loop deal witth all of them? no exceptions ???&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Oct 2017 08:44:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-all-dataset-variables-using-loop/m-p/406847#M99121</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-10-24T08:44:49Z</dc:date>
    </item>
    <item>
      <title>Re: Replace all dataset variables using loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-all-dataset-variables-using-loop/m-p/406849#M99123</link>
      <description>&lt;P&gt;I wouldn't do this in a loop - you can create a macro variable holding the rename string and then execute this with Proc Datasets as in the code below NB correct capitalisation is vital in Proc SQL&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data inputset;
	length dataperiod $5 food 8 house 8 material 8;
	infile datalines dlm=",";
	input dataperiod $ food house material $;
	datalines;
Year1,1,5,8
Year2,8,3,2
Year3,3,2,7
;
run;


DATA outputset;
	set inputset;
	Food = dif(Food);
	House = dif(House);
	Material=dif(Material);
run;

proc sql noprint;
	select cats(name,'=','dif',name)
	into :varlist
	separated by ' '
	from dictionary.columns
	where libname= 'WORK' and memname= 'INPUTSET' and name ne 'dataperiod';
quit;

%put &amp;amp;varlist;

proc datasets lib=work;
modify outputset;
rename &amp;amp;varlist;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Oct 2017 08:51:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-all-dataset-variables-using-loop/m-p/406849#M99123</guid>
      <dc:creator>ChrisBrooks</dc:creator>
      <dc:date>2017-10-24T08:51:47Z</dc:date>
    </item>
    <item>
      <title>Re: Replace all dataset variables using loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-all-dataset-variables-using-loop/m-p/406851#M99125</link>
      <description>&lt;P&gt;Thanks for your quick reply.&lt;/P&gt;&lt;P&gt;What I mean is that I figure there should be a way of saying&lt;/P&gt;&lt;P&gt;"For ALL variables/column headers X1, X2, X3 etc, with no exception,&amp;nbsp;add&amp;nbsp;the word "dif_" to the variable name so that they are called dif_X1, dif_X2, dif_X3 etc, and calculate &lt;EM&gt;first difference &lt;/EM&gt;for each value. Put all of this in a new dataset called "outputset"".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;BR&lt;/P&gt;&lt;P&gt;Hermina&lt;/P&gt;</description>
      <pubDate>Tue, 24 Oct 2017 09:07:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-all-dataset-variables-using-loop/m-p/406851#M99125</guid>
      <dc:creator>hermina</dc:creator>
      <dc:date>2017-10-24T09:07:02Z</dc:date>
    </item>
    <item>
      <title>Re: Replace all dataset variables using loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-all-dataset-variables-using-loop/m-p/406857#M99127</link>
      <description>&lt;P&gt;So which part of my code does not do what you expect?&lt;/P&gt;</description>
      <pubDate>Tue, 24 Oct 2017 09:22:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-all-dataset-variables-using-loop/m-p/406857#M99127</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-10-24T09:22:47Z</dc:date>
    </item>
    <item>
      <title>Re: Replace all dataset variables using loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-all-dataset-variables-using-loop/m-p/406875#M99131</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/168146"&gt;@hermina&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;What you're asking for can be done but it's on the advanced side and involves SAS Macro coding.&lt;/P&gt;
&lt;P&gt;If you are a beginner then don't go there yet. It doesn't hurt to write a bit more code but then to end up with something that you can easily understand and maintain.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The most "basic" code version could look like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want1;
  infile datalines truncover dlm=' ';
  input Dataperiod $ Food House Material;
  dif_food = food - lag(food);
  dif_house = house - lag(house);
  dif_material = material - lag(material);
  datalines;
Year1 1 5 8
Year2 8 3 9
Year3 3 2 7
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That's basically what&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88384"&gt;@Shmuel&lt;/a&gt;&amp;nbsp;proposed and if your'e new to SAS then that's what you should be doing in my opinion.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to take it one step further you could use array processing as done below:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want2(drop=_:);
  infile datalines truncover dlm=' ';
  input Dataperiod $ Food House Material;
  array source {*} Food House Material;
  array target {*} dif_food dif_house dif_material;
  do _i=1 to dim(source);
    target[_i]= source[_i]-lag(source[_i]);
  end;
  datalines;
Year1 1 5 8
Year2 8 3 9
Year3 3 2 7
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The next step would be SAS macro coding which would allow you to dynamically create your &lt;EM&gt;dif_&lt;/EM&gt; variables. But if you're rather new to SAS then I strongly recommend that you don't go there as it will create more harm than good for you and I won't even post sample code for such an option.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Should you be an experienced programmer and just new to the SAS language then let us know. That's another situation and happy to&amp;nbsp;provide you with&amp;nbsp;the necessary hints how to generate dynamic code using SAS. But if you don't have this background then get first expertise in Base SAS language before you dive into SAS Macro language or you'll end up "very confused and in a mess".&lt;/P&gt;</description>
      <pubDate>Tue, 24 Oct 2017 09:59:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-all-dataset-variables-using-loop/m-p/406875#M99131</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-10-24T09:59:48Z</dc:date>
    </item>
    <item>
      <title>Re: Replace all dataset variables using loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-all-dataset-variables-using-loop/m-p/407191#M99211</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/168146"&gt;@hermina&lt;/a&gt;, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;:&lt;/P&gt;&lt;P&gt;RW9's solution looks good to me, except that you&amp;nbsp;want the new variable names prefixed with "diff_". Which is easily accomplished with a prefix= option in the final PROC TRANSPOSE:&lt;/P&gt;&lt;PRE&gt;data have;
  input dataperiod $ food      house      material;
datalines;
Year1      1      5      8
Year2      8      3      8
Year3      3      2      7
;
run;

proc transpose data=have out=inter;
  by dataperiod;
  var _numeric_;
run;
proc sort data=inter;
  by _name_ dataperiod;
run;
data inter;
  set inter;
  by _name_;
  diff=dif(col1);
  if first._name_ then diff=.;
run;
proc sort data=inter;
  by dataperiod _name_;
run;
proc transpose data=inter out=want(drop=name) prefix=diff_;
  by dataperiod;
  var diff;
  id _name_;
run;&lt;/PRE&gt;&lt;P&gt;And then I put in a drop=name option on the final output, you do not need the name of the temporary variable repeated.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Oct 2017 10:27:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-all-dataset-variables-using-loop/m-p/407191#M99211</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2017-10-25T10:27:37Z</dc:date>
    </item>
    <item>
      <title>Re: Replace all dataset variables using loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-all-dataset-variables-using-loop/m-p/407192#M99212</link>
      <description>Sorry, should have been drop=_name_, not drop=name</description>
      <pubDate>Wed, 25 Oct 2017 10:29:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-all-dataset-variables-using-loop/m-p/407192#M99212</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2017-10-25T10:29:37Z</dc:date>
    </item>
    <item>
      <title>Re: Replace all dataset variables using loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-all-dataset-variables-using-loop/m-p/407280#M99229</link>
      <description>&lt;P&gt;Here is a way to achieve your task of (1) renaming selected vars to have DIF_&amp;nbsp; prefixed to their name, and (2) getting a difference series, without any direct macro programming:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=sashelp.stocks (drop=date obs=0) out=t;
  var _numeric_;
run;

filename tmp temp;
data _null_;
  set t;
  file tmp;
  put _name_ '=dif_' _name_;
run;

data need/view=need;
  set sashelp.stocks;
  rename  %include tmp ;;
run;

data want;
  set need;
  by stock;
  array x {*} dif_: ;
  do I=1 to dim(x);   x{I}=dif(x{I}); end;
  if first.stock then call missing (of x{*});
  drop I;
run;
  &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;The first proc transpose does nothing but get the varnames of interest in dataset T, stored in variable _NAME_.&amp;nbsp; That's why it has the "obs=0" data set name parameter.&lt;/LI&gt;
&lt;LI&gt;The data _null_ step creates a temporary raw file with a list of&amp;nbsp;&amp;nbsp; &lt;EM&gt;&lt;STRONG&gt;X=dif_X&lt;/STRONG&gt;&lt;/EM&gt;&amp;nbsp; expressions for every variable name X found in T.&lt;/LI&gt;
&lt;LI&gt;The data view step renames the variables by %INCLUDing the raw file as part of a rename statement.&amp;nbsp; The rename statement&amp;nbsp; has two semicolons - one to terminate the %include, and one to terminate the RENAME statement that has the %include as a component.&amp;nbsp; It's a data set view, not a data set file, so virtually no resources are required.&amp;nbsp; It looks like a separated step, but is not activated (instantiated in object programming terms) until it is referred to in the next data step.&amp;nbsp; Having a bunch of variables now named "DIF_..." makes array declaration easier in the subsequent data step.&lt;/LI&gt;
&lt;LI&gt;The DATA want step loops over all vars with names starting as "DIF_", creating your desired values.&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Wed, 25 Oct 2017 14:01:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-all-dataset-variables-using-loop/m-p/407280#M99229</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-10-25T14:01:47Z</dc:date>
    </item>
    <item>
      <title>Re: Replace all dataset variables using loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-all-dataset-variables-using-loop/m-p/407965#M99469</link>
      <description>&lt;P&gt;Sorry, it did work just fine! Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 27 Oct 2017 09:47:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-all-dataset-variables-using-loop/m-p/407965#M99469</guid>
      <dc:creator>hermina</dc:creator>
      <dc:date>2017-10-27T09:47:15Z</dc:date>
    </item>
    <item>
      <title>Re: Replace all dataset variables using loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-all-dataset-variables-using-loop/m-p/408164#M99556</link>
      <description>&lt;P&gt;Here is a very intriguing technique.&amp;nbsp; Instead of a SET statement this program uses the MODIFY statement.&amp;nbsp; This means that a data set is modified in place (much like PROC APPEND, or the APPEND statement in PROC DATASETS).&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One of the benefits of the MODIFY statement is than an OUTPUT statement appends a records.&amp;nbsp; So when MODIFY CLASS (below) reads record 1, the OUTPUT statement appends a copy of record 1 to the end of the data set.&amp;nbsp; The MODIFY statement will progress from record 1 through the (original) end of the data set.&amp;nbsp; It will then encounter the newly appended records.&amp;nbsp; The output statement will append those new records, in the order encountered.&amp;nbsp; So here is a very compact way to make 4,003 copies of the datasets:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data class;
  set sashelp.class;
run;

%let copies=4003;
data class;
  modify class nobs=nrecs;
  if _n_&amp;gt; nrecs*(%eval(&amp;amp;copies-1)) then stop;
  output;  /* Append a record */
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 27 Oct 2017 20:31:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-all-dataset-variables-using-loop/m-p/408164#M99556</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-10-27T20:31:30Z</dc:date>
    </item>
  </channel>
</rss>

