<?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 Proc means with a macro variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-means-with-a-macro-variable/m-p/555873#M154760</link>
    <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have to do lot of proc means changing variables one by one on a macro.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is it possible to say something like :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%do variable = "firstVar of the macro variable" %to "lastVar of the macro variable" &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This is an extract of a code :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro data_niv ;

	%DO i = 1 %TO 3 ;

		proc means data = data_niv&amp;amp;i noprint ;
			class cniv1_cniv&amp;amp;i ;
			var cim_q1_i1_ ;
			where cim_q1_i1_ ne . ;
			OUTPUT OUT=resALL N=resall;
		run ;
			
		proc means data = data_niv&amp;amp;i noprint;
			class cniv1_cniv&amp;amp;i ;
			var cim_q1_i1_ ;
			where cim_q1_i1_ in(1);
			OUTPUT OUT=resTS N=resTS;
		run ;	

%END ;

%mend ;	&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;As you can see, i put mi first variable "cim_q1_i1" and it's work. But I have lot a variables and i have these variables names on a macro variable called "var_name" but i don't know how execute one by one each variable of the list..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Onizuka&lt;/P&gt;</description>
    <pubDate>Fri, 03 May 2019 09:43:12 GMT</pubDate>
    <dc:creator>Onizuka</dc:creator>
    <dc:date>2019-05-03T09:43:12Z</dc:date>
    <item>
      <title>Proc means with a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-means-with-a-macro-variable/m-p/555873#M154760</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have to do lot of proc means changing variables one by one on a macro.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is it possible to say something like :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%do variable = "firstVar of the macro variable" %to "lastVar of the macro variable" &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This is an extract of a code :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro data_niv ;

	%DO i = 1 %TO 3 ;

		proc means data = data_niv&amp;amp;i noprint ;
			class cniv1_cniv&amp;amp;i ;
			var cim_q1_i1_ ;
			where cim_q1_i1_ ne . ;
			OUTPUT OUT=resALL N=resall;
		run ;
			
		proc means data = data_niv&amp;amp;i noprint;
			class cniv1_cniv&amp;amp;i ;
			var cim_q1_i1_ ;
			where cim_q1_i1_ in(1);
			OUTPUT OUT=resTS N=resTS;
		run ;	

%END ;

%mend ;	&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;As you can see, i put mi first variable "cim_q1_i1" and it's work. But I have lot a variables and i have these variables names on a macro variable called "var_name" but i don't know how execute one by one each variable of the list..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Onizuka&lt;/P&gt;</description>
      <pubDate>Fri, 03 May 2019 09:43:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-means-with-a-macro-variable/m-p/555873#M154760</guid>
      <dc:creator>Onizuka</dc:creator>
      <dc:date>2019-05-03T09:43:12Z</dc:date>
    </item>
    <item>
      <title>Re: Proc means with a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-means-with-a-macro-variable/m-p/555876#M154762</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use a counter and the %scan functions to retrive the successive elements of your list :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro loop(vars);
&lt;BR /&gt;    %local i;&lt;BR /&gt;
    %do i=1 %to %sysfunc(countw(&amp;amp;vars.));
        %let var=%scan(&amp;amp;vars.,&amp;amp;i.);
        %put &amp;amp;=var.;
    %end;

%mend loop;

%loop(foo bar baz);
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 03 May 2019 10:01:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-means-with-a-macro-variable/m-p/555876#M154762</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2019-05-03T10:01:28Z</dc:date>
    </item>
    <item>
      <title>Re: Proc means with a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-means-with-a-macro-variable/m-p/555879#M154763</link>
      <description>&lt;P&gt;Thank you very much &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/30622"&gt;@gamotte&lt;/a&gt;&amp;nbsp; &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 03 May 2019 10:20:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-means-with-a-macro-variable/m-p/555879#M154763</guid>
      <dc:creator>Onizuka</dc:creator>
      <dc:date>2019-05-03T10:20:59Z</dc:date>
    </item>
    <item>
      <title>Re: Proc means with a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-means-with-a-macro-variable/m-p/555908#M154774</link>
      <description>&lt;P&gt;Show an example of your data.&amp;nbsp; I doubt you need all that looping and can reduce the number of call to PROC MEANS.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 May 2019 12:49:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-means-with-a-macro-variable/m-p/555908#M154774</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2019-05-03T12:49:11Z</dc:date>
    </item>
    <item>
      <title>Re: Proc means with a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-means-with-a-macro-variable/m-p/555923#M154782</link>
      <description>&lt;P&gt;Hello &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Thank you for reply &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15410"&gt;@data_null__&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It's a little hard for me to show you an example of data because there is toooo much data ^^&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For information, know that in the real code, there are 5 proc means (and not 2) &lt;img id="catlol" class="emoticon emoticon-catlol" src="https://communities.sas.com/i/smilies/16x16_cat-lol.png" alt="Cat LOL" title="Cat LOL" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know that I can optimize the code but i'm trying first to make it work haha&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro data_niv ;

	%DO i = 1 %TO 3 ;


		Proc sort data = mca.ajout_cle_niveau out = test ; by cniv1_cniv&amp;amp;i ; run ;

		Data data_niv&amp;amp;i ;
			set test ;
				where cniv1_cniv&amp;amp;i ne "" ;
				where lastPeriode&amp;amp;i ne . ;
			by cniv1_cniv&amp;amp;i ;
			if date &amp;gt;= dt_deb_periode_niv&amp;amp;i ;
		run ;


		%do j = 1 %to %sysfunc(countw(&amp;amp;var_tsi.));
		%let var = %scan(&amp;amp;var_tsi.,&amp;amp;j.);
		
				proc means data = data_niv&amp;amp;i noprint ;
					class cniv1_cniv&amp;amp;i ;
					var &amp;amp;var. ;
					where &amp;amp;var. ne . ;
					OUTPUT OUT=resALL N=&amp;amp;var._resall;
				run ;
					
				proc means data = data_niv&amp;amp;i noprint;
					class cniv1_cniv&amp;amp;i ;
					var &amp;amp;var. ;
					where &amp;amp;var. in(1);
					OUTPUT OUT=resTS N=&amp;amp;var._resTS;
				run ;		

				proc means data = data_niv&amp;amp;i noprint;
					class cniv1_cniv&amp;amp;i ;
					var &amp;amp;var. ;
					where &amp;amp;var. in(2);
					OUTPUT OUT=resS N=&amp;amp;var._resS;
				run ;

				proc means data = data_niv&amp;amp;i noprint;
					class cniv1_cniv&amp;amp;i ;
					var &amp;amp;var. ;
					where &amp;amp;var. in(3);
					OUTPUT OUT=resI N=&amp;amp;var._resI ;
				run ;			

				proc means data = data_niv&amp;amp;i noprint;
					class cniv1_cniv&amp;amp;i ;
					var &amp;amp;var. ;
					where &amp;amp;var. in(4);
					OUTPUT OUT=resTI N=&amp;amp;var._resTI;


				data synthese_&amp;amp;var._niv&amp;amp;i. ;
					merge resALL resTS resS resI resTI;
					by cniv1_cniv&amp;amp;i ;

						if &amp;amp;var._resALL ne . then do;

							if &amp;amp;var._resTS = . then &amp;amp;var._resTS = 0 ;
							if &amp;amp;var._resS  = . then &amp;amp;var._resS  = 0 ;
							if &amp;amp;var._resI  = . then &amp;amp;var._resI  = 0 ;
							if &amp;amp;var._resTI = . then &amp;amp;var._resTI = 0 ;

							&amp;amp;var._resTSI = ( &amp;amp;var._resTS - ( &amp;amp;var._resI + &amp;amp;var._resTI )) / &amp;amp;var._resall ;
							&amp;amp;var._resTS  = &amp;amp;var._resTS / &amp;amp;var._resall ;
							&amp;amp;var._resS   = &amp;amp;var._resS  / &amp;amp;var._resall ;
							&amp;amp;var._resI   = &amp;amp;var._resI  / &amp;amp;var._resall ;
							&amp;amp;var._resTI  = &amp;amp;var._resTI / &amp;amp;var._resall ;

						end;

					if &amp;amp;var._resALL = . then delete ;
					if cniv1_cniv&amp;amp;i = "" then delete ;
					drop _type_ _freq_ ;
				run ;


				Data synthese_&amp;amp;var._niv&amp;amp;i. (rename=(cniv1_cniv&amp;amp;i = code_niv));
					set synthese_&amp;amp;var._niv&amp;amp;i. ;

						format question $20. ;
						question = "&amp;amp;var."; ;
						zone = "cniv&amp;amp;i" ;

				run ;
		/* I'm working on this step below */		
				%if &amp;amp;j = 1 %then %do ;
					Data test1 ;
					set synthese_&amp;amp;var._niv&amp;amp;i.;
					run ;
				%end ;
				%else %do ;
					Proc sql ;
					insert into test1 
					select * from synthese_&amp;amp;var._niv&amp;amp;i. 
					quit ;
				%end ;

		%end ;

	%END ;

%mend data_niv ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 03 May 2019 13:30:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-means-with-a-macro-variable/m-p/555923#M154782</guid>
      <dc:creator>Onizuka</dc:creator>
      <dc:date>2019-05-03T13:30:47Z</dc:date>
    </item>
    <item>
      <title>Re: Proc means with a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-means-with-a-macro-variable/m-p/555936#M154785</link>
      <description>&lt;P&gt;I do not suggest that you would show all of your data.&amp;nbsp; If you have a lot of data reducing the number of times you read it becomes more important.&amp;nbsp; I'm sure you know best.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 May 2019 14:10:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-means-with-a-macro-variable/m-p/555936#M154785</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2019-05-03T14:10:50Z</dc:date>
    </item>
    <item>
      <title>Re: Proc means with a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-means-with-a-macro-variable/m-p/555937#M154786</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15410"&gt;@data_null__&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;I do not suggest that you would show all of your data.&amp;nbsp; If you have a lot of data reducing the number of times you read it becomes more important.&amp;nbsp; I'm sure you know best.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;I will try !! When my code works, I will come back here for some advice for optimize the code &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thank you &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;&amp;nbsp;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 May 2019 14:18:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-means-with-a-macro-variable/m-p/555937#M154786</guid>
      <dc:creator>Onizuka</dc:creator>
      <dc:date>2019-05-03T14:18:53Z</dc:date>
    </item>
  </channel>
</rss>

