<?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 select the name of column in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/select-the-name-of-column/m-p/683415#M206994</link>
    <description>&lt;PRE&gt;%macro kpi(variable,have_1,have_2,want);

proc sql;
create want have_1 as
select distinct 1 as have_1,sum(&amp;amp;variable) as error
from &amp;amp;have_1;
quit;

proc sql;
create want have_2 as
select distinct 1 as have_2,sum(&amp;amp;variable) as Total
from &amp;amp;have_2;
quit;

proc sql;
create want &amp;amp;want as
select "(I want to select here the name of &amp;amp;variable)", t1.error ,t2.Total, t1.error/t2.Total format=percent8.2 as Pourcentage
from have_1 t1
inner join have_2 t2 on (t1.have_1=t2.have_2);
quit;

proc delete data=have_2 have_1;
run;

%mend;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Hello, I want to select the name of column as value.&lt;/P&gt;</description>
    <pubDate>Sat, 12 Sep 2020 09:05:25 GMT</pubDate>
    <dc:creator>mazouz</dc:creator>
    <dc:date>2020-09-12T09:05:25Z</dc:date>
    <item>
      <title>select the name of column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/select-the-name-of-column/m-p/683415#M206994</link>
      <description>&lt;PRE&gt;%macro kpi(variable,have_1,have_2,want);

proc sql;
create want have_1 as
select distinct 1 as have_1,sum(&amp;amp;variable) as error
from &amp;amp;have_1;
quit;

proc sql;
create want have_2 as
select distinct 1 as have_2,sum(&amp;amp;variable) as Total
from &amp;amp;have_2;
quit;

proc sql;
create want &amp;amp;want as
select "(I want to select here the name of &amp;amp;variable)", t1.error ,t2.Total, t1.error/t2.Total format=percent8.2 as Pourcentage
from have_1 t1
inner join have_2 t2 on (t1.have_1=t2.have_2);
quit;

proc delete data=have_2 have_1;
run;

%mend;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Hello, I want to select the name of column as value.&lt;/P&gt;</description>
      <pubDate>Sat, 12 Sep 2020 09:05:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/select-the-name-of-column/m-p/683415#M206994</guid>
      <dc:creator>mazouz</dc:creator>
      <dc:date>2020-09-12T09:05:25Z</dc:date>
    </item>
    <item>
      <title>Re: select the name of column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/select-the-name-of-column/m-p/683418#M206997</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/339736"&gt;@mazouz&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try omitting the double quotes around &amp;amp;variable.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 12 Sep 2020 09:30:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/select-the-name-of-column/m-p/683418#M206997</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2020-09-12T09:30:26Z</dc:date>
    </item>
    <item>
      <title>Re: select the name of column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/select-the-name-of-column/m-p/683420#M206999</link>
      <description>&lt;P&gt;Erreur de syntaxe, don't work&lt;/P&gt;</description>
      <pubDate>Sat, 12 Sep 2020 09:55:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/select-the-name-of-column/m-p/683420#M206999</guid>
      <dc:creator>mazouz</dc:creator>
      <dc:date>2020-09-12T09:55:22Z</dc:date>
    </item>
    <item>
      <title>Re: select the name of column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/select-the-name-of-column/m-p/683423#M207001</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/339736"&gt;@mazouz&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then something else might be wrong, because the following works:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	id = 1; othervar = 'jean'; error = 3; output;
	id = 2; othervar = 'hans'; error = 5; output;
run;

%macro kpi(variable,have_1,want);
	proc sql;
		create table &amp;amp;want as
		select t1.&amp;amp;variable, t1.error
		from &amp;amp;have_1 t1;
	quit;
	%mend;
%kpi;

%kpi(othervar,have,test);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Output:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="test.gif" style="width: 216px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/49305iEDCF2A34E109EE7A/image-size/large?v=v2&amp;amp;px=999" role="button" title="test.gif" alt="test.gif" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 12 Sep 2020 10:13:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/select-the-name-of-column/m-p/683423#M207001</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2020-09-12T10:13:20Z</dc:date>
    </item>
    <item>
      <title>Re: select the name of column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/select-the-name-of-column/m-p/683424#M207002</link>
      <description>&lt;P&gt;First of all, &lt;STRONG&gt;ALWAYS&lt;/STRONG&gt; start with code that works before trying to make it dynamic. Errors in that non-macro code are much easier to find by studying the log (Maxim 2).&lt;/P&gt;
&lt;PRE&gt; 72         
 73         proc sql;
 74         create want have_1 as
                   ____
                   22
                   76
 ERROR 22-322: Syntaxfehler, erwartet wird eines der folgenden: DISTINCT, INDEX, TABLE, UNIQUE, VIEW.  
 
 ERROR 76-322: Syntax error, statement will be ignored.
&lt;/PRE&gt;
&lt;P&gt;The marker clearly shows that PROC SQL wants something else instead of the "want" here.&lt;/P&gt;
&lt;P&gt;So let's apply Maxim 1 (Read the Documentation):&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=sqlproc&amp;amp;docsetTarget=n1oihmdy7om5rmn1aorxui3kxizl.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;SQL Procedure&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and we find that the CREATE keyword must be followed by either TABLE, INDEX or VIEW and a name, so you have to alter your code to&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want_have_1 as
select distinct 1 as have_1,sum(&amp;amp;variable) as error
from &amp;amp;have_1;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The next thing that hits my eye very painfully is your use of DISTINCT, which makes no sense here, as you will get only one observation anyway from this SELECT; omit it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Next, the join is bogus; you only have 1 observation from both intermediate datasets, both have a 1 in the key variable, so this is crushing peanuts with an elephant's hoof.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You only want a sum from each dataset, and calculate the rate between them, so that can easily be done in one select with a sub-select:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro kpi(variable,have_1,have_2,want);

proc sql;
create table &amp;amp;want. as
  select
    "&amp;amp;variable." as name,
    sum(&amp;amp;variable.) as error,
    (select sum(&amp;amp;variable. from &amp;amp;have_2.)) as total,
    calculated error / calculated total format=percent8.2 as Pourcentage
  from &amp;amp;have_1.
;
quit;

%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 12 Sep 2020 10:22:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/select-the-name-of-column/m-p/683424#M207002</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-09-12T10:22:01Z</dc:date>
    </item>
    <item>
      <title>Re: select the name of column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/select-the-name-of-column/m-p/683425#M207003</link>
      <description>&lt;P&gt;WARNING: Multiple lengths were specified for the variable name by input data set(s). This can cause truncation of data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp; I want to keep same lenghts of columns names&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;&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>Sat, 12 Sep 2020 10:56:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/select-the-name-of-column/m-p/683425#M207003</guid>
      <dc:creator>mazouz</dc:creator>
      <dc:date>2020-09-12T10:56:48Z</dc:date>
    </item>
    <item>
      <title>Re: select the name of column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/select-the-name-of-column/m-p/683429#M207005</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/339736"&gt;@mazouz&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;WARNING: Multiple lengths were specified for the variable name by input data set(s). This can cause truncation of data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp; I want to keep same lenghts of columns names&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Then set one with a length=option in the SELECT.&lt;/P&gt;</description>
      <pubDate>Sat, 12 Sep 2020 11:14:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/select-the-name-of-column/m-p/683429#M207005</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-09-12T11:14:08Z</dc:date>
    </item>
  </channel>
</rss>

