<?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 questions about quotes in variables and parameters in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/questions-about-quotes-in-variables-and-parameters/m-p/970414#M46023</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Sorry for my poor english i'm beginner with SAS and i am blocked with a stupid error in my program&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have troubles with values i want to pass in a SQL request with a variable :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%do x = 1 %to %EVAL(%sysfunc(COUNTC(&amp;amp;liste_tables,' ')) + 1); /* to pass all the table list */&lt;/P&gt;&lt;P&gt;%let curr_table = %scan(&amp;amp;liste_tables,&amp;amp;x);&lt;/P&gt;&lt;P&gt;create table travail as select *&amp;nbsp;from &amp;amp;curr_table.;&lt;/P&gt;&lt;P&gt;/* works fine */&lt;/P&gt;&lt;P&gt;insert into compteurs select &amp;amp;curr_table. as table, count(*) as nb from travail&lt;/P&gt;&lt;P&gt;/* doesn't work because the value of curr_table is not a field in the table travail, i just want to pass the value of the table to insert it&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think it's because there are no quotes in my value, but i don't find how to put quotes, i tried quotes(&amp;amp;curr_table,"'") without success&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks for your help, regards&lt;/P&gt;</description>
    <pubDate>Wed, 09 Jul 2025 07:52:52 GMT</pubDate>
    <dc:creator>davmarol78</dc:creator>
    <dc:date>2025-07-09T07:52:52Z</dc:date>
    <item>
      <title>questions about quotes in variables and parameters</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/questions-about-quotes-in-variables-and-parameters/m-p/970414#M46023</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Sorry for my poor english i'm beginner with SAS and i am blocked with a stupid error in my program&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have troubles with values i want to pass in a SQL request with a variable :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%do x = 1 %to %EVAL(%sysfunc(COUNTC(&amp;amp;liste_tables,' ')) + 1); /* to pass all the table list */&lt;/P&gt;&lt;P&gt;%let curr_table = %scan(&amp;amp;liste_tables,&amp;amp;x);&lt;/P&gt;&lt;P&gt;create table travail as select *&amp;nbsp;from &amp;amp;curr_table.;&lt;/P&gt;&lt;P&gt;/* works fine */&lt;/P&gt;&lt;P&gt;insert into compteurs select &amp;amp;curr_table. as table, count(*) as nb from travail&lt;/P&gt;&lt;P&gt;/* doesn't work because the value of curr_table is not a field in the table travail, i just want to pass the value of the table to insert it&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think it's because there are no quotes in my value, but i don't find how to put quotes, i tried quotes(&amp;amp;curr_table,"'") without success&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks for your help, regards&lt;/P&gt;</description>
      <pubDate>Wed, 09 Jul 2025 07:52:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/questions-about-quotes-in-variables-and-parameters/m-p/970414#M46023</guid>
      <dc:creator>davmarol78</dc:creator>
      <dc:date>2025-07-09T07:52:52Z</dc:date>
    </item>
    <item>
      <title>Re: questions about quotes in variables and parameters</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/questions-about-quotes-in-variables-and-parameters/m-p/970416#M46024</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for sharing your code. So that we can try to help you better, please also carry out the following:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Submit &lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;options mprint symbolgen;&lt;/FONT&gt; &lt;/STRONG&gt;to show what the macro is generating and then submit the code you posted again.&lt;/LI&gt;
&lt;LI&gt;Post the full log of the code and any messages (especially errors) using the Insert Code icon "&amp;lt;/&amp;gt;".&lt;/LI&gt;
&lt;LI&gt;Please provide an example of the correct text that you want to see generated.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks &amp;amp; kind regards,&lt;/P&gt;
&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Jul 2025 09:13:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/questions-about-quotes-in-variables-and-parameters/m-p/970416#M46024</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2025-07-09T09:13:41Z</dc:date>
    </item>
    <item>
      <title>Re: questions about quotes in variables and parameters</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/questions-about-quotes-in-variables-and-parameters/m-p/970421#M46028</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/476159"&gt;@davmarol78&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;it looks like you are looking for something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test(liste_tables);

%local x curr_table;

data compteurs; 
  length table $ 41 nb 8;
  stop;
run;

PROC SQL;
%do x = 1 %to %sysfunc(COUNTW(&amp;amp;liste_tables,%str( ))); /* to pass all the table list */
%let curr_table = %scan(&amp;amp;liste_tables,&amp;amp;x,%str( ));

create table travail as select * from &amp;amp;curr_table.;

/* works fine */

insert into compteurs select "&amp;amp;curr_table." as table, count(*) as nb from travail;

%end;

QUIT;

%mend test;

%test(sashelp.class sashelp.cars sashelp.iris)

proc print data = compteurs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but! if you are really interested in getting tables metadata, and they are SAS tables, consider using SQL's DICTIONARY tables, for example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select memname, nobs from DICTIONARY.TABLES
where libname = "SASHELP";
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;you can filter them, and do it more efficient than opening each table and counting observations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Wed, 09 Jul 2025 09:49:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/questions-about-quotes-in-variables-and-parameters/m-p/970421#M46028</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2025-07-09T09:49:57Z</dc:date>
    </item>
    <item>
      <title>Re: questions about quotes in variables and parameters</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/questions-about-quotes-in-variables-and-parameters/m-p/970422#M46029</link>
      <description>&lt;P&gt;Hi Amir and thaks i hope to be clear&lt;/P&gt;&lt;P&gt;I have my dataset LISTE_TABLE which contains all the tables i want to scan&lt;/P&gt;&lt;P&gt;For my test it only contains the table "test_table"&lt;/P&gt;&lt;P&gt;The result is to have this dataset COMPTEURS :&lt;/P&gt;&lt;P&gt;table&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;nb_avant&lt;/P&gt;&lt;P&gt;test_table&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 136850&lt;/P&gt;&lt;P&gt;with&amp;nbsp;136850 the number of rows of my table "test_table"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;30         %MACRO test();
31         
32         proc sql;
33         	create table COMPTEURS(table char(40), nb_avant num(8), nb_apres_att num(8), nb_purge_att num(8), nb_apres_obt num(8),
33       ! nb_purge_obt num(8));
34         	select DATASET_A_TRAITER into :liste_tables separated by ' '
35         	from LISTE_TABLES;
36         quit;
37         
38         %do x = 1 %to %EVAL(%sysfunc(COUNTC(&amp;amp;liste_tables,' ')) + 1);
39         	%let curr_table = %scan(&amp;amp;liste_tables,&amp;amp;x);
40         	proc sql;
41         	insert into COMPTEURS (table, nb_avant)
42         			select &amp;amp;curr_table. as table, count(*) as nb_avant from TRAVAIL
43         	;
44         	quit;
45         %end;
46         
47         %MEND test;
48         
49         %test();
MPRINT(TEST):   proc sql;
MPRINT(TEST):   create table COMPTEURS(table char(40), nb_avant num(8), nb_apres_att num(8), nb_purge_att num(8), nb_apres_obt 
num(8), nb_purge_obt num(8));
NOTE: Table WORK.COMPTEURS created, with 0 rows and 6 columns.
MPRINT(TEST):   select DATASET_A_TRAITER into :liste_tables separated by ' ' from LISTE_TABLES;
MPRINT(TEST):   quit;
NOTE: PROCEDURE SQL a utilisé (Durée totale du traitement) :
      real time           0.00 seconds
      cpu time            0.01 seconds
      

SYMBOLGEN:  La macro-variable LISTE_TABLES est résolue en test_table 
SYMBOLGEN:  La macro-variable LISTE_TABLES est résolue en test_table 
SYMBOLGEN:  La macro-variable X est résolue en 1
MPRINT(TEST):   proc sql;
SYMBOLGEN:  La macro-variable CURR_TABLE est résolue en test_table
MPRINT(TEST):   insert into COMPTEURS (table, nb_avant) select test_table as table, count(*) as nb_avant from TRAVAIL ;
ERROR: Les colonnes suivantes sont introuvables dans les tables de contribution : test_table.
ERROR: Les colonnes suivantes sont introuvables dans les tables de contribution : test_table.
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
MPRINT(TEST):   quit;
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SQL a utilisé (Durée totale du traitement) :
      real time           0.00 seconds
      cpu time            0.01 seconds
      
50         options mprint symbolgen;
51         
52         %LET _CLIENTTASKLABEL=;
53         %LET _CLIENTPROCESSFLOWNAME=;
54         %LET _CLIENTPROJECTPATH=;
55         %LET _CLIENTPROJECTPATHHOST=;
56         %LET _CLIENTPROJECTNAME=;
57         %LET _SASPROGRAMFILE=;
58         %LET _SASPROGRAMFILEHOST=;
59         
60         ;*';*";*/;quit;run;
3                                                          Le Système SAS                              09:12 Wednesday, July 9, 2025

61         ODS _ALL_ CLOSE;
62         
63         
64         QUIT; RUN;
65         &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 09 Jul 2025 09:52:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/questions-about-quotes-in-variables-and-parameters/m-p/970422#M46029</guid>
      <dc:creator>davmarol78</dc:creator>
      <dc:date>2025-07-09T09:52:02Z</dc:date>
    </item>
    <item>
      <title>Re: questions about quotes in variables and parameters</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/questions-about-quotes-in-variables-and-parameters/m-p/970424#M46030</link>
      <description>&lt;P&gt;Hi Bart,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;works fine ! thanks a lot i was stupidly blocked with this story of quotes...&lt;/P&gt;&lt;P&gt;in fact i don't just want to have the number of lines of my table, i have to use them for a further traitment&lt;/P&gt;</description>
      <pubDate>Wed, 09 Jul 2025 09:54:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/questions-about-quotes-in-variables-and-parameters/m-p/970424#M46030</guid>
      <dc:creator>davmarol78</dc:creator>
      <dc:date>2025-07-09T09:54:38Z</dc:date>
    </item>
    <item>
      <title>Re: questions about quotes in variables and parameters</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/questions-about-quotes-in-variables-and-parameters/m-p/970453#M46033</link>
      <description>&lt;P&gt;What are you trying to do with this complex equation?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; %EVAL(%sysfunc(COUNTC(&amp;amp;liste_tables,' ')) + 1)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Let's break it down. So first it counts how many times either of the two characters space and single quote appear in the macro variable.&amp;nbsp; Then it adds one.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since you seem to be using it as the upper bound for a %DO loop that processes each item in a list why not just use the &lt;STRONG&gt;COUNTW() function&lt;/STRONG&gt; to find out how many items are in the list instead?&amp;nbsp; Also &lt;STRONG&gt;make sure to use the same set of characters as delimiters in both&lt;/STRONG&gt; the call to COUNTW() and the call to %SCAN().&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%do x = 1 %to %sysfunc(COUNTW(&amp;amp;liste_tables,%str( )));
  %let curr_table = %scan(&amp;amp;liste_tables,&amp;amp;x,%str( ));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 09 Jul 2025 15:37:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/questions-about-quotes-in-variables-and-parameters/m-p/970453#M46033</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-07-09T15:37:28Z</dc:date>
    </item>
  </channel>
</rss>

