<?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: rename all variables based on one column value in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/rename-all-variables-based-on-one-column-value/m-p/842010#M332930</link>
    <description>&lt;P&gt;Hi, thank you for your codes!&lt;/P&gt;
&lt;P&gt;However, variables were just renamed to "_12m" instead of selected based on the session. I was wondering what would be the issue.&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;here is the code:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data one;
   input id  age session score1 score2 score3;
   datalines;
1 10 1 85 90 89
1  10 2 95 100 99
2  11 1 99 98 91
2   11 2 99 98 91
3  12 1 100 100 100
3  12 2 60 70 80
4   11 1 78 89 100
4 11 2 88 99 120
;
run;

%if &amp;amp;session = 1
%then %do;
%let suff = _bl;
%end;
%else %if &amp;amp;session=2 %do;
%let suff = _12m;
%end;

proc sql noprint;
select catx("=",name,cats(name,"&amp;amp;suff.")) into :renames separated by " "
from dictionary.columns
where libname = "WORK" and memname = "ONE";
quit;

proc datasets lib=work;
modify one;
rename &amp;amp;renames.;
quit;&lt;/PRE&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Here is the log:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;763 %if &amp;amp;session = 1&lt;BR /&gt;WARNING: Apparent symbolic reference SESSION not resolved.&lt;BR /&gt;764 %then %do;&lt;BR /&gt;WARNING: Apparent symbolic reference SESSION not resolved.&lt;BR /&gt;ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric&lt;BR /&gt;operand is required. The condition was: &amp;amp;session = 1&lt;BR /&gt;ERROR: Skipping to next %END statement.&lt;BR /&gt;765 %let suff = _bl;&lt;BR /&gt;766 %end;&lt;BR /&gt;767 %else %if &amp;amp;session=2 %do;&lt;BR /&gt;ERROR: Nesting of %IF statements in open code is not supported. %IF ignored.&lt;BR /&gt;ERROR: Skipping to next %END statement.&lt;BR /&gt;768 %let suff = _12m;&lt;BR /&gt;769 %end;&lt;BR /&gt;770&lt;/P&gt;</description>
    <pubDate>Wed, 02 Nov 2022 01:21:43 GMT</pubDate>
    <dc:creator>aw016</dc:creator>
    <dc:date>2022-11-02T01:21:43Z</dc:date>
    <item>
      <title>rename all variables based on one column value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/rename-all-variables-based-on-one-column-value/m-p/841984#M332913</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am trying to rename variables altogether based on the "session" value.&lt;/P&gt;&lt;P&gt;If session=1 then all variables should be var_bl; if session=2 then all variables should be var_12m.&lt;/P&gt;&lt;P&gt;I was wondering how to use concatenate function to do that. Previously I read some similar posts, but couldn't quite understand the algorithm.&lt;/P&gt;&lt;P&gt;Very much appreciate any explanation!!&lt;/P&gt;</description>
      <pubDate>Tue, 01 Nov 2022 21:19:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/rename-all-variables-based-on-one-column-value/m-p/841984#M332913</guid>
      <dc:creator>aw016</dc:creator>
      <dc:date>2022-11-01T21:19:21Z</dc:date>
    </item>
    <item>
      <title>Re: rename all variables based on one column value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/rename-all-variables-based-on-one-column-value/m-p/841988#M332915</link>
      <description>&lt;P&gt;Your question makes no sense. All variables in a dataset must have different names, so you cannot rename them to the same name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have trouble describing your task, post examples for "before" and "after".&lt;/P&gt;</description>
      <pubDate>Tue, 01 Nov 2022 21:35:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/rename-all-variables-based-on-one-column-value/m-p/841988#M332915</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-11-01T21:35:13Z</dc:date>
    </item>
    <item>
      <title>Re: rename all variables based on one column value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/rename-all-variables-based-on-one-column-value/m-p/841989#M332916</link>
      <description>&lt;P&gt;Hi, what I meant is not to rename everything into the same name, but to add a suffix to all variables as "_bl" or "_12m" based on session value.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Nov 2022 21:41:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/rename-all-variables-based-on-one-column-value/m-p/841989#M332916</guid>
      <dc:creator>aw016</dc:creator>
      <dc:date>2022-11-01T21:41:50Z</dc:date>
    </item>
    <item>
      <title>Re: rename all variables based on one column value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/rename-all-variables-based-on-one-column-value/m-p/841990#M332917</link>
      <description>&lt;P&gt;You retrieve the existing names from DICTIONARY.COLUMNS in PROC SQL.&lt;/P&gt;
&lt;P&gt;With SELECT INTO you can build a macro variable which holds the rename pairs, for later use in PROC DATASETS.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if &amp;amp;session = 1
%then %do;
%let suff = _bl;
%end;
%else %do;
%let suff = _12m;
%end;

proc sql noprint;
select catx("=",name,cats(name,"&amp;amp;suff.")) into :renames separated by " "
from dictionary.columns
where libname = "LIBRARY" and memname = "DATASET";
quit;

proc datasets lib=library;
modify dataset;
rename &amp;amp;renames.;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 01 Nov 2022 21:52:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/rename-all-variables-based-on-one-column-value/m-p/841990#M332917</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-11-01T21:52:21Z</dc:date>
    </item>
    <item>
      <title>Re: rename all variables based on one column value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/rename-all-variables-based-on-one-column-value/m-p/842010#M332930</link>
      <description>&lt;P&gt;Hi, thank you for your codes!&lt;/P&gt;
&lt;P&gt;However, variables were just renamed to "_12m" instead of selected based on the session. I was wondering what would be the issue.&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;here is the code:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data one;
   input id  age session score1 score2 score3;
   datalines;
1 10 1 85 90 89
1  10 2 95 100 99
2  11 1 99 98 91
2   11 2 99 98 91
3  12 1 100 100 100
3  12 2 60 70 80
4   11 1 78 89 100
4 11 2 88 99 120
;
run;

%if &amp;amp;session = 1
%then %do;
%let suff = _bl;
%end;
%else %if &amp;amp;session=2 %do;
%let suff = _12m;
%end;

proc sql noprint;
select catx("=",name,cats(name,"&amp;amp;suff.")) into :renames separated by " "
from dictionary.columns
where libname = "WORK" and memname = "ONE";
quit;

proc datasets lib=work;
modify one;
rename &amp;amp;renames.;
quit;&lt;/PRE&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Here is the log:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;763 %if &amp;amp;session = 1&lt;BR /&gt;WARNING: Apparent symbolic reference SESSION not resolved.&lt;BR /&gt;764 %then %do;&lt;BR /&gt;WARNING: Apparent symbolic reference SESSION not resolved.&lt;BR /&gt;ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric&lt;BR /&gt;operand is required. The condition was: &amp;amp;session = 1&lt;BR /&gt;ERROR: Skipping to next %END statement.&lt;BR /&gt;765 %let suff = _bl;&lt;BR /&gt;766 %end;&lt;BR /&gt;767 %else %if &amp;amp;session=2 %do;&lt;BR /&gt;ERROR: Nesting of %IF statements in open code is not supported. %IF ignored.&lt;BR /&gt;ERROR: Skipping to next %END statement.&lt;BR /&gt;768 %let suff = _12m;&lt;BR /&gt;769 %end;&lt;BR /&gt;770&lt;/P&gt;</description>
      <pubDate>Wed, 02 Nov 2022 01:21:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/rename-all-variables-based-on-one-column-value/m-p/842010#M332930</guid>
      <dc:creator>aw016</dc:creator>
      <dc:date>2022-11-02T01:21:43Z</dc:date>
    </item>
    <item>
      <title>Re: rename all variables based on one column value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/rename-all-variables-based-on-one-column-value/m-p/842024#M332935</link>
      <description>&lt;P&gt;You cannot rename conditionally (on the value of a dataset variable). Your question therefore makes even less sense than before.&lt;/P&gt;
&lt;P&gt;Please show the intended result for your example data.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Nov 2022 05:28:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/rename-all-variables-based-on-one-column-value/m-p/842024#M332935</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-11-02T05:28:24Z</dc:date>
    </item>
  </channel>
</rss>

