<?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: Assign the values to a macro variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Assign-the-values-to-a-macro-variable/m-p/955829#M373263</link>
    <description>&lt;P&gt;You could use FINDW() function to replace IN operator:&lt;/P&gt;
&lt;PRE&gt;%macro my_analysis(liste=,nom_part=);

	data base_finale_&amp;amp;nom_part.;
		set base_finale_0;

		if Trimestre="T1" and &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;findw("&amp;amp;liste.",  strip(cd_code) ,' ','it' );&lt;/STRONG&gt;&lt;/FONT&gt;
		keep PM PS PL;
	run;

	proc sort data=base_finale_&amp;amp;nom_part. nodupkey;
		by _all_;
	run;

	proc sql noprint;
		select sum(PL) 
			into :Montant_T1_&amp;amp;nom_part.  
				from base_finale_&amp;amp;nom_part.;
	quit;

	%PUT &amp;amp;&amp;amp;Montant_T1_&amp;amp;nom_part.;

	Data Finale_index;
		Montant_T1_&amp;amp;nom_part.=&amp;amp;&amp;amp;Montant_T1_&amp;amp;nom_part.;
	run;

%mend;

%my_analysis(&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;liste=  C1  C2&lt;/STRONG&gt; &lt;/FONT&gt;,nom_part="PXXX");&lt;/PRE&gt;</description>
    <pubDate>Sun, 12 Jan 2025 02:45:45 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2025-01-12T02:45:45Z</dc:date>
    <item>
      <title>Assign the values to a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-the-values-to-a-macro-variable/m-p/955793#M373247</link>
      <description>&lt;P&gt;Hello Experts,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you know, please, how to assign the multiple values (C1','C2') to te macro variables ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro my_analysis(liste=,nom_part=);

	data base_finale_&amp;amp;nom_part.;
		set base_finale_0;

		if Trimestre="T1" and cd_code in(&amp;amp;liste.);
		keep PM PS PL;
	run;

	proc sort data=base_finale_&amp;amp;nom_part. nodupkey;
		by _all_;
	run;

	proc sql noprint;
		select sum(PL) 
			into :Montant_T1_&amp;amp;nom_part.  
				from base_finale_&amp;amp;nom_part.;
	quit;

	%PUT &amp;amp;&amp;amp;Montant_T1_&amp;amp;nom_part.;

	Data Finale_index;
		Montant_T1_&amp;amp;nom_part.=&amp;amp;&amp;amp;Montant_T1_&amp;amp;nom_part.;
	run;

%mend;

%my_analysis(liste='C1','C2',nom_part="PXXX");&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thank you !&lt;/P&gt;</description>
      <pubDate>Sat, 11 Jan 2025 10:44:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-the-values-to-a-macro-variable/m-p/955793#M373247</guid>
      <dc:creator>SASdevAnneMarie</dc:creator>
      <dc:date>2025-01-11T10:44:22Z</dc:date>
    </item>
    <item>
      <title>Re: Assign the values to a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-the-values-to-a-macro-variable/m-p/955795#M373249</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/286185"&gt;@SASdevAnneMarie&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use blanks to separate the items in macro variable &lt;FONT face="courier new,courier"&gt;liste&lt;/FONT&gt;. The IN operator doesn't need commas and the macro processor doesn't like them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also omit the quotation marks around the value of &lt;FONT face="courier new,courier"&gt;nom_part&lt;/FONT&gt; because they are invalid characters in the name of a dataset or (macro) variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;FONT size="4"&gt;%my_analysis(liste=&lt;STRONG&gt;'C1' 'C2'&lt;/STRONG&gt;,nom_part=&lt;STRONG&gt;PXXX&lt;/STRONG&gt;)&lt;/FONT&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 11 Jan 2025 11:10:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-the-values-to-a-macro-variable/m-p/955795#M373249</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2025-01-11T11:10:09Z</dc:date>
    </item>
    <item>
      <title>Re: Assign the values to a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-the-values-to-a-macro-variable/m-p/955804#M373256</link>
      <description>&lt;P&gt;Another thought to save typing the quotes and avoid the potential of making mistakes when you type the quotes: You can use the %QLIST macro to take your input string in &amp;amp;liste that does not have quotes, and create a new macro variable with single quotes around each item in &amp;amp;liste.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/sasutils/macros/blob/master/qlist.sas" target="_blank" rel="noopener nofollow noreferrer"&gt;https://github.com/sasutils/macros/blob/master/qlist.sas&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, it would look like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename qlist url 'https://raw.githubusercontent.com/sasutils/macros/master/qlist.sas';
%include  qlist;

%macro my_analysis(liste=,nom_part=);

	data base_finale_&amp;amp;nom_part.;
		set base_finale_0;
		if Trimestre="T1" and cd_code in %qlist(&amp;amp;liste.,comma=0);
		keep PM PS PL;
	run;

/* Other code */

%mend;

%my_analysis(liste=C1 C2,nom_part=PXXX)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have only two elements in &amp;amp;LISTE like C1 C2, this code really doesn't save you much typing; if the are 12 elements in &amp;amp;LISTE, this code becomes very helpful, a lot less typing and virtually eliminates the potential of typographical errors when you type the quotes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;NOTE: the filename statement may not work behind some corporate firewalls, in which case you then have to download the QLIST macro as a .SAS program and save it on your hard drive and then %include that file.&lt;/P&gt;</description>
      <pubDate>Sat, 11 Jan 2025 13:53:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-the-values-to-a-macro-variable/m-p/955804#M373256</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-01-11T13:53:12Z</dc:date>
    </item>
    <item>
      <title>Re: Assign the values to a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-the-values-to-a-macro-variable/m-p/955813#M373259</link>
      <description>&lt;P&gt;You can also use parentheses around the value being passed to protect the comma.&lt;/P&gt;
&lt;P&gt;That can work in some places.&amp;nbsp; The IN operator in a data step does not care if there are extra () in the list.&lt;/P&gt;
&lt;PRE&gt;1    %let name=('Alfred','Jane');
2    data want;
3      set sashelp.class;
4      if name in (&amp;amp;name);
5    run;

NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: The data set WORK.WANT has 2 observations and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds
&lt;/PRE&gt;
&lt;P&gt;Extra () do not cause trouble in list of initial values of ARRAY statements either.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But in SQL (and by extension a WHERE statement anywhere) it is more persnickety about it.&lt;/P&gt;
&lt;PRE&gt;6    proc print data=sashelp.class;
7      where name in (&amp;amp;name);
                           -
                           22
                           200
ERROR 22-322: Syntax error, expecting one of the following: ;, !, &amp;amp;, AND, OR, |.
ERROR 200-322: The symbol is not recognized and will be ignored.
NOTE: Line generated by the macro variable "NAME".
1    ('Alfred','Jane')
     -
     22
     200
ERROR: Syntax error while parsing WHERE clause.
ERROR 22-322: Syntax error, expecting one of the following: a quoted string, a numeric constant, a datetime constant,
              a missing value, -.
ERROR 200-322: The symbol is not recognized and will be ignored.
8    run;

NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE PRINT used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds



9    proc sql;
10   select * from sashelp.class
11   where name in (&amp;amp;name);
NOTE: Line generated by the macro variable "NAME".
1    ('Alfred','Jane')
      --------       -
      79             22
                     76
ERROR 79-322: Expecting a SELECT.

ERROR 22-322: Syntax error, expecting one of the following: a quoted string, !, !!, &amp;amp;, *, **, +, ',', -, /, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;=, ?,
              AND, AS, BETWEEN, CONTAINS, EQ, EQT, FORMAT, FROM, GE, GET, GT, GTT, IN, INFORMAT, INTO, IS, LABEL, LE, LEN, LENGTH,
              LET, LIKE, LT, LTT, NE, NET, NOT, NOTIN, OR, TRANSCODE, ^, ^=, |, ||, ~, ~=.

ERROR 76-322: Syntax error, statement will be ignored.

12   quit;
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
&lt;/PRE&gt;</description>
      <pubDate>Sat, 11 Jan 2025 16:08:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-the-values-to-a-macro-variable/m-p/955813#M373259</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-01-11T16:08:36Z</dc:date>
    </item>
    <item>
      <title>Re: Assign the values to a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-the-values-to-a-macro-variable/m-p/955829#M373263</link>
      <description>&lt;P&gt;You could use FINDW() function to replace IN operator:&lt;/P&gt;
&lt;PRE&gt;%macro my_analysis(liste=,nom_part=);

	data base_finale_&amp;amp;nom_part.;
		set base_finale_0;

		if Trimestre="T1" and &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;findw("&amp;amp;liste.",  strip(cd_code) ,' ','it' );&lt;/STRONG&gt;&lt;/FONT&gt;
		keep PM PS PL;
	run;

	proc sort data=base_finale_&amp;amp;nom_part. nodupkey;
		by _all_;
	run;

	proc sql noprint;
		select sum(PL) 
			into :Montant_T1_&amp;amp;nom_part.  
				from base_finale_&amp;amp;nom_part.;
	quit;

	%PUT &amp;amp;&amp;amp;Montant_T1_&amp;amp;nom_part.;

	Data Finale_index;
		Montant_T1_&amp;amp;nom_part.=&amp;amp;&amp;amp;Montant_T1_&amp;amp;nom_part.;
	run;

%mend;

%my_analysis(&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;liste=  C1  C2&lt;/STRONG&gt; &lt;/FONT&gt;,nom_part="PXXX");&lt;/PRE&gt;</description>
      <pubDate>Sun, 12 Jan 2025 02:45:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-the-values-to-a-macro-variable/m-p/955829#M373263</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-01-12T02:45:45Z</dc:date>
    </item>
  </channel>
</rss>

