<?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: Problem using call symputx by variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Problem-using-call-symputx-by-variable/m-p/562307#M157513</link>
    <description>&lt;P&gt;In general it is not a good idea to transfer values into macro variables just so you can later translate them back into values.&lt;/P&gt;
&lt;P&gt;Keep the data in datasets.&amp;nbsp; Your code is not consistently referencing the same input dataset, but most likely you want to summarize the values&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data summary;    
   set pourcomptage ;  
   by cniv1_cniv3 ; 
   if first.cniv1_cniv3 then first_value=col1;
   if last.cniv1_cniv3 then do ; 
      last_value=sumcum;
      output;
   end;
   retain first_value;
   keep cniv1-cniv3 first_value last_value;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and then merge/join the summary data back with the other data.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql ;
create table indi_cm as 
  select a.cniv1_cniv3, a.variable
       , (sum(count)/(b.first_value - b.last_value) as percent_mod
  from nb_niv a
  left join summary b 
  on a.cniv1_cniv3 = b.cniv1_cniv3
  group by a.cniv1_cniv3, a.variable 
;
quit ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 29 May 2019 14:49:15 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2019-05-29T14:49:15Z</dc:date>
    <item>
      <title>Problem using call symputx by variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-using-call-symputx-by-variable/m-p/562298#M157506</link>
      <description>&lt;P&gt;Hello !&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sorry for my english..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can we create many macro variables using the BY VARIABLE... ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried something like this :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test888;   
set pourcomptage ;  
	by cniv1_cniv3 ; 

	if first.cniv1_cniv3 then do ;
		call symputx("V1",col1); 
	end ;

	if last.cniv1_cniv3 then do ; 
		call symputx('V2',sumcum);    
	end ;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The problem is that when i want to call the both macro variable, juste the last macro variable is stored.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;These 2 macro variables permit me to calculate later the difference : %let nrep = %eval(&amp;amp;v1 - &amp;amp;v2) and then, on a SQL QUERY, calculate by hand, a percent by variable (cniv1_cniv3).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I'm doing this :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let nrep = %eval(&amp;amp;V1 - &amp;amp;V2) ;

Proc sql ;
create table indi_cm as 
select cniv1_cniv3, variable, (sum(count)/&amp;amp;nrep) as percent_mod
from nb_niv
group by cniv1_cniv3, variable ;
quit ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I don't know how to say : "for the first cniv1_cniv3 you take the first &amp;amp;nrep associate to this cniv1_cniv3"&lt;/P&gt;&lt;P&gt;"for the second cniv1_cniv3, you take the second &amp;amp;nrep" .....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you have any idea ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't put an example of data because I think that you can help me without !&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Onizuka&lt;/P&gt;</description>
      <pubDate>Wed, 29 May 2019 14:36:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-using-call-symputx-by-variable/m-p/562298#M157506</guid>
      <dc:creator>Onizuka</dc:creator>
      <dc:date>2019-05-29T14:36:36Z</dc:date>
    </item>
    <item>
      <title>Re: Problem using call symputx by variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-using-call-symputx-by-variable/m-p/562305#M157512</link>
      <description>&lt;P&gt;This is exactly what the macro engine is NOT for. Forget that macros exist at all (for the moment), you need to learn handling the Base SAS language first.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test888;   
set pourcomptage ;  
by cniv1_cniv3 ; 
retain _col1;
if first.cniv1_cniv3 then _col1 = col1;
if last.cniv1_cniv3 then do ; 
  diff = sumcum - _col1; /* or whatever you want to calculate for the group */
  output;
end ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 29 May 2019 14:45:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-using-call-symputx-by-variable/m-p/562305#M157512</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-05-29T14:45:19Z</dc:date>
    </item>
    <item>
      <title>Re: Problem using call symputx by variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-using-call-symputx-by-variable/m-p/562307#M157513</link>
      <description>&lt;P&gt;In general it is not a good idea to transfer values into macro variables just so you can later translate them back into values.&lt;/P&gt;
&lt;P&gt;Keep the data in datasets.&amp;nbsp; Your code is not consistently referencing the same input dataset, but most likely you want to summarize the values&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data summary;    
   set pourcomptage ;  
   by cniv1_cniv3 ; 
   if first.cniv1_cniv3 then first_value=col1;
   if last.cniv1_cniv3 then do ; 
      last_value=sumcum;
      output;
   end;
   retain first_value;
   keep cniv1-cniv3 first_value last_value;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and then merge/join the summary data back with the other data.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql ;
create table indi_cm as 
  select a.cniv1_cniv3, a.variable
       , (sum(count)/(b.first_value - b.last_value) as percent_mod
  from nb_niv a
  left join summary b 
  on a.cniv1_cniv3 = b.cniv1_cniv3
  group by a.cniv1_cniv3, a.variable 
;
quit ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 29 May 2019 14:49:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-using-call-symputx-by-variable/m-p/562307#M157513</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-05-29T14:49:15Z</dc:date>
    </item>
    <item>
      <title>Re: Problem using call symputx by variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-using-call-symputx-by-variable/m-p/562343#M157520</link>
      <description>&amp;gt;I don't put an example of data because I think that you can help me without !&lt;BR /&gt;&lt;BR /&gt;It's significantly easier to help you with it though.</description>
      <pubDate>Wed, 29 May 2019 16:29:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-using-call-symputx-by-variable/m-p/562343#M157520</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-05-29T16:29:41Z</dc:date>
    </item>
    <item>
      <title>Re: Problem using call symputx by variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-using-call-symputx-by-variable/m-p/562789#M157703</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you a lot for all you responses, I think that the solution of &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt; is working perfectly and so as the solution of &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt; !&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't know why I didn't think about doing a simple merge... !&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried to do something similar, I did not think for a single second to the instruction "output"&lt;/P&gt;</description>
      <pubDate>Fri, 31 May 2019 07:27:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-using-call-symputx-by-variable/m-p/562789#M157703</guid>
      <dc:creator>Onizuka</dc:creator>
      <dc:date>2019-05-31T07:27:25Z</dc:date>
    </item>
  </channel>
</rss>

