<?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: get the number from the column name, like symget in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/get-the-number-from-the-column-name-like-symget/m-p/633326#M187874</link>
    <description>&lt;P&gt;Certainly using several functions, many times, on every observation will run up the bill.&amp;nbsp; It would be wiser to put in the programming effort up front:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%macro getn;
&amp;nbsp; &amp;nbsp;%local i;
&amp;nbsp; &amp;nbsp;%do i=1 %to 4;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;amp;&amp;amp;n&amp;amp;i
&amp;nbsp; &amp;nbsp;%end;
%mend&amp;nbsp;getn;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;With that work done, you could use this macro in your original program to replace one line:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array c {4} _temporary_ (%getn);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;With that array in place, your program should work without any further changes.&lt;/P&gt;</description>
    <pubDate>Thu, 19 Mar 2020 15:35:20 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2020-03-19T15:35:20Z</dc:date>
    <item>
      <title>get the number from the column name, like symget</title>
      <link>https://communities.sas.com/t5/SAS-Programming/get-the-number-from-the-column-name-like-symget/m-p/633191#M187821</link>
      <description>&lt;P&gt;to calculate&amp;nbsp;the percent from&amp;nbsp;the tables&amp;nbsp;as below,&lt;/P&gt;
&lt;P&gt;pct1=co1/n1;&lt;/P&gt;
&lt;P&gt;pct2=col2/n2;&lt;/P&gt;
&lt;P&gt;pct3.........&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE style="width: 240pt; border-collapse: collapse;" border="0" width="320" cellspacing="0" cellpadding="0"&gt;&lt;COLGROUP&gt;&lt;COL style="width: 48pt;" span="5" width="64" /&gt;&lt;/COLGROUP&gt;
&lt;TBODY&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD width="64" height="17" style="border: 0.5pt solid windowtext; width: 48pt; height: 12.75pt; background-color: transparent;"&gt;&lt;FONT size="2" color="#000000"&gt;ord&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="64" style="border-width: 0.5pt 0.5pt 0.5pt 0px; border-style: solid solid solid none; border-color: windowtext; width: 48pt; background-color: transparent;"&gt;&lt;FONT size="2" color="#000000"&gt;col1&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="64" style="border-width: 0.5pt 0.5pt 0.5pt 0px; border-style: solid solid solid none; border-color: windowtext; width: 48pt; background-color: transparent;"&gt;&lt;FONT size="2" color="#000000"&gt;col2&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="64" style="border-width: 0.5pt 0.5pt 0.5pt 0px; border-style: solid solid solid none; border-color: windowtext; width: 48pt; background-color: transparent;"&gt;&lt;FONT size="2" color="#000000"&gt;col3&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="64" style="border-width: 0.5pt 0.5pt 0.5pt 0px; border-style: solid solid solid none; border-color: windowtext; width: 48pt; background-color: transparent;"&gt;&lt;FONT size="2" color="#000000"&gt;col4&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD height="17" align="right" style="border-width: 0px 0.5pt 0.5pt; border-style: none solid solid; border-color: windowtext; height: 12.75pt; background-color: transparent;"&gt;&lt;FONT size="2" color="#000000"&gt;1&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border-width: 0px 0.5pt 0.5pt 0px; border-style: none solid solid none; border-color: windowtext; background-color: transparent;"&gt;&lt;FONT size="2" color="#000000"&gt;10&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border-width: 0px 0.5pt 0.5pt 0px; border-style: none solid solid none; border-color: windowtext; background-color: transparent;"&gt;&lt;FONT size="2" color="#000000"&gt;20&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border-width: 0px 0.5pt 0.5pt 0px; border-style: none solid solid none; border-color: windowtext; background-color: transparent;"&gt;&lt;FONT size="2" color="#000000"&gt;53&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border-width: 0px 0.5pt 0.5pt 0px; border-style: none solid solid none; border-color: windowtext; background-color: transparent;"&gt;&lt;FONT size="2" color="#000000"&gt;32&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD height="17" align="right" style="border-width: 0px 0.5pt 0.5pt; border-style: none solid solid; border-color: windowtext; height: 12.75pt; background-color: transparent;"&gt;&lt;FONT size="2" color="#000000"&gt;2&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border-width: 0px 0.5pt 0.5pt 0px; border-style: none solid solid none; border-color: windowtext; background-color: transparent;"&gt;&lt;FONT size="2" color="#000000"&gt;7&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border-width: 0px 0.5pt 0.5pt 0px; border-style: none solid solid none; border-color: windowtext; background-color: transparent;"&gt;&lt;FONT size="2" color="#000000"&gt;15&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border-width: 0px 0.5pt 0.5pt 0px; border-style: none solid solid none; border-color: windowtext; background-color: transparent;"&gt;&lt;FONT size="2" color="#000000"&gt;30&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border-width: 0px 0.5pt 0.5pt 0px; border-style: none solid solid none; border-color: windowtext; background-color: transparent;"&gt;&lt;FONT size="2" color="#000000"&gt;40&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD height="17" align="right" style="border-width: 0px 0.5pt 0.5pt; border-style: none solid solid; border-color: windowtext; height: 12.75pt; background-color: transparent;"&gt;&lt;FONT size="2" color="#000000"&gt;3&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border-width: 0px 0.5pt 0.5pt 0px; border-style: none solid solid none; border-color: windowtext; background-color: transparent;"&gt;&lt;FONT size="2" color="#000000"&gt;10&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border-width: 0px 0.5pt 0.5pt 0px; border-style: none solid solid none; border-color: windowtext; background-color: transparent;"&gt;&lt;FONT size="2" color="#000000"&gt;20&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border-width: 0px 0.5pt 0.5pt 0px; border-style: none solid solid none; border-color: windowtext; background-color: transparent;"&gt;&lt;FONT size="2" color="#000000"&gt;31&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border-width: 0px 0.5pt 0.5pt 0px; border-style: none solid solid none; border-color: windowtext; background-color: transparent;"&gt;&lt;FONT size="2" color="#000000"&gt;43&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD height="17" align="right" style="border-width: 0px 0.5pt 0.5pt; border-style: none solid solid; border-color: windowtext; height: 12.75pt; background-color: transparent;"&gt;&lt;FONT size="2" color="#000000"&gt;4&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border-width: 0px 0.5pt 0.5pt 0px; border-style: none solid solid none; border-color: windowtext; background-color: transparent;"&gt;&lt;FONT size="2" color="#000000"&gt;15&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border-width: 0px 0.5pt 0.5pt 0px; border-style: none solid solid none; border-color: windowtext; background-color: transparent;"&gt;&lt;FONT size="2" color="#000000"&gt;25&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border-width: 0px 0.5pt 0.5pt 0px; border-style: none solid solid none; border-color: windowtext; background-color: transparent;"&gt;&lt;FONT size="2" color="#000000"&gt;30&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border-width: 0px 0.5pt 0.5pt 0px; border-style: none solid solid none; border-color: windowtext; background-color: transparent;"&gt;&lt;FONT size="2" color="#000000"&gt;40&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD height="17" align="right" style="border-width: 0px 0.5pt 0.5pt; border-style: none solid solid; border-color: windowtext; height: 12.75pt; background-color: transparent;"&gt;&lt;FONT size="2" color="#000000"&gt;5&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border-width: 0px 0.5pt 0.5pt 0px; border-style: none solid solid none; border-color: windowtext; background-color: transparent;"&gt;&lt;FONT size="2" color="#000000"&gt;19&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border-width: 0px 0.5pt 0.5pt 0px; border-style: none solid solid none; border-color: windowtext; background-color: transparent;"&gt;&lt;FONT size="2" color="#000000"&gt;40&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border-width: 0px 0.5pt 0.5pt 0px; border-style: none solid solid none; border-color: windowtext; background-color: transparent;"&gt;&lt;FONT size="2" color="#000000"&gt;23&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border-width: 0px 0.5pt 0.5pt 0px; border-style: none solid solid none; border-color: windowtext; background-color: transparent;"&gt;&lt;FONT size="2" color="#000000"&gt;50&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;n1-n5 are macro variables: &amp;amp;n1,,,&amp;amp;n4&lt;/P&gt;
&lt;TABLE style="width: 96pt; border-collapse: collapse;" border="0" width="128" cellspacing="0" cellpadding="0"&gt;&lt;COLGROUP&gt;&lt;COL style="width: 48pt;" span="2" width="64" /&gt;&lt;/COLGROUP&gt;
&lt;TBODY&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD width="64" height="17" style="border: 0.5pt solid windowtext; width: 48pt; height: 12.75pt; background-color: transparent;"&gt;&lt;FONT size="2" color="#000000"&gt;total&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="64" style="border-width: 0.5pt 0.5pt 0.5pt 0px; border-style: solid solid solid none; border-color: windowtext; width: 48pt; background-color: transparent;"&gt;&lt;FONT size="2" color="#000000"&gt;　&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD height="17" style="border-width: 0px 0.5pt 0.5pt; border-style: none solid solid; border-color: windowtext; height: 12.75pt; background-color: transparent;"&gt;&lt;FONT size="2" color="#000000"&gt;n1&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border-width: 0px 0.5pt 0.5pt 0px; border-style: none solid solid none; border-color: windowtext; background-color: transparent;"&gt;&lt;FONT size="2" color="#000000"&gt;100&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD height="17" style="border-width: 0px 0.5pt 0.5pt; border-style: none solid solid; border-color: windowtext; height: 12.75pt; background-color: transparent;"&gt;&lt;FONT size="2" color="#000000"&gt;n2&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border-width: 0px 0.5pt 0.5pt 0px; border-style: none solid solid none; border-color: windowtext; background-color: transparent;"&gt;&lt;FONT size="2" color="#000000"&gt;200&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD height="17" style="border-width: 0px 0.5pt 0.5pt; border-style: none solid solid; border-color: windowtext; height: 12.75pt; background-color: transparent;"&gt;&lt;FONT size="2" color="#000000"&gt;n3&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border-width: 0px 0.5pt 0.5pt 0px; border-style: none solid solid none; border-color: windowtext; background-color: transparent;"&gt;&lt;FONT size="2" color="#000000"&gt;300&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD height="17" style="border-width: 0px 0.5pt 0.5pt; border-style: none solid solid; border-color: windowtext; height: 12.75pt; background-color: transparent;"&gt;&lt;FONT size="2" color="#000000"&gt;n4&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border-width: 0px 0.5pt 0.5pt 0px; border-style: none solid solid none; border-color: windowtext; background-color: transparent;"&gt;&lt;FONT size="2" color="#000000"&gt;400&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&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 have;
input ord col1 col2 col3 col4 ;
cards;
1 5 10 6 30
2 17 15 7 25
3 20 25 8 40
;
run;


%let n1=100;
%let n2=200;
%let n3=100;
%let n4=200;

%macro pct();
data pct;
	set have;
	array a col1-col4;
	array b pct1-pct4;
	array c &amp;amp;n1- &amp;amp;n4 ;
	do i=1 to 4;
		b(i)=a(i)/c(i);
	end;
run;
%mend;
%pct;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;the code doesn't work due to warning, don't use&amp;nbsp;proc transpose.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*is there a funciton */
data pct2;
	set have;
	pct{funtion(col(i)}=col{funtion(col(i)}/n{funtion(col(i)};
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Mar 2020 09:55:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/get-the-number-from-the-column-name-like-symget/m-p/633191#M187821</guid>
      <dc:creator>blueskyxyz</dc:creator>
      <dc:date>2020-03-19T09:55:35Z</dc:date>
    </item>
    <item>
      <title>Re: get the number from the column name, like symget</title>
      <link>https://communities.sas.com/t5/SAS-Programming/get-the-number-from-the-column-name-like-symget/m-p/633206#M187828</link>
      <description>&lt;P&gt;Why not use proc transpose, when it is the tool of choice?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyway, you need to correctly create an array with values:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want1;
	set have;
	array a col1-col4;
	array b pct1-pct4;
	array c {4} _temporary_ (&amp;amp;n1 &amp;amp;n2 &amp;amp;n3 &amp;amp;n4);
	do i=1 to 4;
		b(i)=a(i)/c(i);
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;using transpose:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data percentages;
input index n;
datalines;
1 100
2 200
3 100
4 200
;

proc transpose data=have out=trans;
by ord;
var col:;
run;

data trans2;
set trans;
if 0 then set percentages;
if _n_ = 1
then do;
  declare hash h (dataset:'percentages');
  h.definekey('index');
  h.definedata('n');
  h.definedone();
end;
index = input(compress(_name_,'','kd'),best.);
if h.find() = 0 then pct = col1 / n;
run;

proc transpose data=trans2 out=pct (drop=_name_) prefix=pct;
by ord;
var pct;
run;

data want2;
merge
  have
  pct
;
by ord;
run;

proc compare base=want1 compare=want2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The transpose method is completely data-driven and makes no assumptions about the number of elements anywhere in the code.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Mar 2020 10:30:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/get-the-number-from-the-column-name-like-symget/m-p/633206#M187828</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-03-19T10:30:17Z</dc:date>
    </item>
    <item>
      <title>Re: get the number from the column name, like symget</title>
      <link>https://communities.sas.com/t5/SAS-Programming/get-the-number-from-the-column-name-like-symget/m-p/633209#M187830</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/298115"&gt;@blueskyxyz&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your idea to use SYMGET works as well:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data pct(drop=i);
set have;
array col[4];
array pct[4];
do i=1 to 4;
  pct[i]=col[i]/input(symget(cats('n',i)),32.);
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Mar 2020 10:49:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/get-the-number-from-the-column-name-like-symget/m-p/633209#M187830</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-03-19T10:49:10Z</dc:date>
    </item>
    <item>
      <title>Re: get the number from the column name, like symget</title>
      <link>https://communities.sas.com/t5/SAS-Programming/get-the-number-from-the-column-name-like-symget/m-p/633326#M187874</link>
      <description>&lt;P&gt;Certainly using several functions, many times, on every observation will run up the bill.&amp;nbsp; It would be wiser to put in the programming effort up front:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%macro getn;
&amp;nbsp; &amp;nbsp;%local i;
&amp;nbsp; &amp;nbsp;%do i=1 %to 4;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;amp;&amp;amp;n&amp;amp;i
&amp;nbsp; &amp;nbsp;%end;
%mend&amp;nbsp;getn;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;With that work done, you could use this macro in your original program to replace one line:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array c {4} _temporary_ (%getn);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;With that array in place, your program should work without any further changes.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Mar 2020 15:35:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/get-the-number-from-the-column-name-like-symget/m-p/633326#M187874</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2020-03-19T15:35:20Z</dc:date>
    </item>
    <item>
      <title>Re: get the number from the column name, like symget</title>
      <link>https://communities.sas.com/t5/SAS-Programming/get-the-number-from-the-column-name-like-symget/m-p/636104#M188915</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt; , thank you, sir.</description>
      <pubDate>Tue, 31 Mar 2020 06:59:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/get-the-number-from-the-column-name-like-symget/m-p/636104#M188915</guid>
      <dc:creator>blueskyxyz</dc:creator>
      <dc:date>2020-03-31T06:59:02Z</dc:date>
    </item>
    <item>
      <title>Re: get the number from the column name, like symget</title>
      <link>https://communities.sas.com/t5/SAS-Programming/get-the-number-from-the-column-name-like-symget/m-p/636106#M188916</link>
      <description>thanks all friends for this question,  to use array, symget, transpose to get the percent.&lt;BR /&gt; sorry, the new version can only pick one as answer???</description>
      <pubDate>Tue, 31 Mar 2020 07:04:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/get-the-number-from-the-column-name-like-symget/m-p/636106#M188916</guid>
      <dc:creator>blueskyxyz</dc:creator>
      <dc:date>2020-03-31T07:04:02Z</dc:date>
    </item>
  </channel>
</rss>

