<?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 variables with points or propose another calculation approach in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Rename-variables-with-points-or-propose-another-calculation/m-p/899994#M355687</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
   select cats(quote(trim(name)),'n = ',quote(compress(trim(name),'.')),'n') into :renames separated by ' ' 
   from dictionary.columns where libname='WORK' and memname="MATABLE" and type='char';
quit;
%put &amp;amp;=renames;

proc datasets library=work nolist;
    modify matable;
    rename &amp;amp;renames;
run; quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 25 Oct 2023 16:49:29 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2023-10-25T16:49:29Z</dc:date>
    <item>
      <title>Rename variables with points or propose another calculation approach</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-variables-with-points-or-propose-another-calculation/m-p/899982#M355678</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data MaTable;
   input Nom $ "A.D.C_EF"n $ Score_biomarqueur Score_pesticides "Q13t"n $ "Q13bist"n $ "Q1.A"n $ "Qt.2"n $;
   datalines;
   Doe John 30 1 oui o T i
   Smith Jane 25 20 oui n T o
   Brown Alice 35 2 non n T o
   A C 2 2 non n K j
   A C 5 23 non n K j
   B John 10 21 non n K l
   K C 31 13 oui o K l
   B Jane 21 4 non o S l
;
run; 

%macro stat_central();
proc sql ;
   select name into :char_vars separated by ' ' 
   from dictionary.columns where libname='WORK' and memname="MATABLE" and type='char';
quit;  

%put &amp;amp;char_vars.;  
%do k=1 %to %sysfunc(countw(&amp;amp;char_vars.));
    %let char = %scan(&amp;amp;char_vars., &amp;amp;k.); 
	proc sort data=MATABLE;
	by "&amp;amp;char."n;
	run;
	proc means data=MATABLE;
var Score_biomarqueur Score_pesticides;
class "&amp;amp;char."n;
run;
%end; 
%mend;  

%stat_central();&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Here is an extract from my table. I want to run this macro program but I get an error message because of the variables having dots. In fact, these variables separate into 2 or more variables. As a result, SAS no longer finds them in the base.&lt;/P&gt;
&lt;P&gt;Can anyone help me solve this problem or suggest another approach?&lt;/P&gt;
&lt;P&gt;Note that this is just an extract from the table. I have several variable names written with periods.&lt;/P&gt;
&lt;P&gt;Best regards,&lt;BR /&gt;Gick&lt;/P&gt;</description>
      <pubDate>Wed, 25 Oct 2023 15:03:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-variables-with-points-or-propose-another-calculation/m-p/899982#M355678</guid>
      <dc:creator>Gick</dc:creator>
      <dc:date>2023-10-25T15:03:27Z</dc:date>
    </item>
    <item>
      <title>Re: Rename variables with points or propose another calculation approach</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-variables-with-points-or-propose-another-calculation/m-p/899983#M355679</link>
      <description>&lt;P&gt;You need to tell the macro to split words using the space character.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%do k=1 %to %sysfunc(countw(&amp;amp;char_vars.,%str( )));
    %let char = %scan(&amp;amp;char_vars., &amp;amp;k.,%str( )); 
&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;Why a macro anyway? PROC MEANS/PROC SUMMARY can split the data by each class variable without macros, which also has the benefit of passing through the data only once, which might make a difference if you have very large data sets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc sql ;
   select cats(quote(trim(name),"'"),'n') into :char_vars separated by ' '
   from dictionary.columns where libname='WORK' and memname="MATABLE" and type='char';
quit;
%put &amp;amp;=char_vars;

proc means data=matable;
    var Score_biomarqueur Score_pesticides;
    class &amp;amp;char_vars;
    ways 1;
run;&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In general, I almost always avoid using dots and the like in variable names, if the database forces me to use dots or similar, I will usually rename the variables before I try to do other programming with them.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Oct 2023 15:22:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-variables-with-points-or-propose-another-calculation/m-p/899983#M355679</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-10-25T15:22:00Z</dc:date>
    </item>
    <item>
      <title>Re: Rename variables with points or propose another calculation approach</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-variables-with-points-or-propose-another-calculation/m-p/899990#M355683</link>
      <description>Of course. even I rename first but there are several (more than 100 variables) like that</description>
      <pubDate>Wed, 25 Oct 2023 15:29:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-variables-with-points-or-propose-another-calculation/m-p/899990#M355683</guid>
      <dc:creator>Gick</dc:creator>
      <dc:date>2023-10-25T15:29:07Z</dc:date>
    </item>
    <item>
      <title>Re: Rename variables with points or propose another calculation approach</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-variables-with-points-or-propose-another-calculation/m-p/899994#M355687</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
   select cats(quote(trim(name)),'n = ',quote(compress(trim(name),'.')),'n') into :renames separated by ' ' 
   from dictionary.columns where libname='WORK' and memname="MATABLE" and type='char';
quit;
%put &amp;amp;=renames;

proc datasets library=work nolist;
    modify matable;
    rename &amp;amp;renames;
run; quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 25 Oct 2023 16:49:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-variables-with-points-or-propose-another-calculation/m-p/899994#M355687</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-10-25T16:49:29Z</dc:date>
    </item>
    <item>
      <title>Re: Rename variables with points or propose another calculation approach</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-variables-with-points-or-propose-another-calculation/m-p/899997#M355690</link>
      <description>However the code returns the results to me several times. In fact, as many variables, as many results are repeated.</description>
      <pubDate>Wed, 25 Oct 2023 15:42:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-variables-with-points-or-propose-another-calculation/m-p/899997#M355690</guid>
      <dc:creator>Gick</dc:creator>
      <dc:date>2023-10-25T15:42:20Z</dc:date>
    </item>
    <item>
      <title>Re: Rename variables with points or propose another calculation approach</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-variables-with-points-or-propose-another-calculation/m-p/900003#M355692</link>
      <description>&lt;P&gt;Most simple solution: don't allow these stupid name literals in the first place. Funny strings belong in labels.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Oct 2023 16:21:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-variables-with-points-or-propose-another-calculation/m-p/900003#M355692</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-10-25T16:21:28Z</dc:date>
    </item>
    <item>
      <title>Re: Rename variables with points or propose another calculation approach</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-variables-with-points-or-propose-another-calculation/m-p/900005#M355694</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/416124"&gt;@Gick&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;However the code returns the results to me several times. In fact, as many variables, as many results are repeated.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I don't know what this means. Show us the code. Show us the output.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Oct 2023 16:45:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-variables-with-points-or-propose-another-calculation/m-p/900005#M355694</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-10-25T16:45:39Z</dc:date>
    </item>
    <item>
      <title>Re: Rename variables with points or propose another calculation approach</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-variables-with-points-or-propose-another-calculation/m-p/900012#M355701</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data MaTable;
    input Nom $ "A.D.C_EF"n $ Score_biomarqueur Score_pesticides 
        "Q13t"n $ "Q13bist"n $ "Q1.A"n $ "Qt.2"n $;
    datalines;
   Doe John 30 1 oui o T i
   Smith Jane 25 20 oui n T o
   Brown Alice 35 2 non n T o
   A C 2 2 non n K j
   A C 5 23 non n K j
   B John 10 21 non n K l
   K C 31 13 oui o K l
   B Jane 21 4 non o S l
;
run;

%macro stat_central();
    proc sql;
        select nliteral(name) into :char_vars separated by '|' from 
            dictionary.columns where libname='WORK' and memname="MATABLE" and 
            type='char';
    quit;

    %put &amp;amp;char_vars.;

    %do k=1 %to %sysfunc(countw(&amp;amp;char_vars., |));
        %let char = %scan(&amp;amp;char_vars., &amp;amp;k., |);
        %put &amp;amp;char.;

        proc sort data=MATABLE;
            by &amp;amp;char.;
        run;

        proc means data=MATABLE;
            class &amp;amp;char.;
            var Score_biomarqueur Score_pesticides;
        run;

    %end;
%mend;

%stat_central();&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;Use NLITERAL to get the name in a valid naming format.&lt;/P&gt;
&lt;P&gt;Use a delimiter that is not a space to delimit the list.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Add the delimiter specification to the COUNTW().&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But you can also do this using CLASS and a WAYS statement without the loops and use _character_ to reference character variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;        proc means data=MATABLE;
            class _character_;
            ways 1;
            var Score_biomarqueur Score_pesticides;
        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, 25 Oct 2023 17:38:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-variables-with-points-or-propose-another-calculation/m-p/900012#M355701</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-10-25T17:38:18Z</dc:date>
    </item>
    <item>
      <title>Re: Rename variables with points or propose another calculation approach</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-variables-with-points-or-propose-another-calculation/m-p/900057#M355719</link>
      <description>&lt;P&gt;And you don't need to re-count the number of names.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PROC SQL already counted them for you. so just remember that number.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select nliteral(name)
  into :char_vars separated by '|' 
from dictionary.columns 
where libname='WORK'
  and memname="MATABLE"
  and type='char'
;
%let nvars=&amp;amp;sqlobs;
quit;

%do i=1 %to &amp;amp;nvars;
...&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 26 Oct 2023 02:11:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-variables-with-points-or-propose-another-calculation/m-p/900057#M355719</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-10-26T02:11:26Z</dc:date>
    </item>
  </channel>
</rss>

