<?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: Using PROC SQL &amp;amp;quot;into;&amp;amp;quot; , then using SYMPUT with a long macrovariable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-PROC-SQL-amp-quot-into-amp-quot-then-using-SYMPUT-with-a/m-p/959373#M374308</link>
    <description>&lt;P&gt;I would go with:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data foo;
    string = symget("Cit_S_string");
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
    <pubDate>Mon, 17 Feb 2025 15:46:35 GMT</pubDate>
    <dc:creator>yabwon</dc:creator>
    <dc:date>2025-02-17T15:46:35Z</dc:date>
    <item>
      <title>Using PROC SQL &amp;quot;into;&amp;quot; , then using SYMPUT with a long macrovariable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-PROC-SQL-amp-quot-into-amp-quot-then-using-SYMPUT-with-a/m-p/959366#M374302</link>
      <description>&lt;P&gt;Hi SAS Friends,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Need help bringing a long complex macrovariable into a SAS dataset.&lt;/P&gt;&lt;P&gt;Attached is a file with 2 columns.&amp;nbsp;&lt;/P&gt;&lt;P&gt;One column is an index (NO_) and the other (Cit_S)&amp;nbsp; is a variable containing names and years separated by ",".&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cit_S variables need to be brought together into a single long variable, each separated by a ";", and then that brought into a SAS dataset.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have been using Proc SQL with an "into;" statement, which works very well to create a single macrovariable.&amp;nbsp;&lt;/P&gt;&lt;P&gt;However am stuck on how to bring the marcrovariable back into SAS.&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I use SYMPUT within a datastep, to import macrovariable "&amp;amp;Cit_S_string", there are multiple errors related to the variable length and the presence of semicolons, .....that am stuck on.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Would appreciate your help with this,&lt;/P&gt;&lt;P&gt;Attached is a sample dataset and the PROC SQL code&lt;/P&gt;&lt;P&gt;Thank you,&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;R&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc sql;	
	select Cit_S	 
	into:Cit_S_string separated by ";" from sf.test;	
	quit;
%put Cit_S_string	= "&amp;amp;Cit_S_string";&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Feb 2025 14:44:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-PROC-SQL-amp-quot-into-amp-quot-then-using-SYMPUT-with-a/m-p/959366#M374302</guid>
      <dc:creator>rmacarthur</dc:creator>
      <dc:date>2025-02-17T14:44:00Z</dc:date>
    </item>
    <item>
      <title>Re: Using PROC SQL &amp;quot;into;&amp;quot; , then using SYMPUT with a long macrovariable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-PROC-SQL-amp-quot-into-amp-quot-then-using-SYMPUT-with-a/m-p/959368#M374304</link>
      <description>&lt;P&gt;Hey&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/28361"&gt;@rmacarthur&lt;/a&gt;! You do not need to use &lt;EM&gt;symput&lt;/EM&gt; to bring a macro variable into a SAS dataset. &lt;EM&gt;Symput&lt;/EM&gt; creates macro variables from the DATA Step, kind of like the SQL &lt;EM&gt;into&lt;/EM&gt; statement. A macro variable can be thought of as just a reference to text. You can resolve that reference by putting an &amp;amp; in front of the variable name. For example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data foo;
    string = "&amp;amp;Cit_S_string";
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Can you post your DATA Step code as well?&lt;/P&gt;</description>
      <pubDate>Mon, 17 Feb 2025 14:51:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-PROC-SQL-amp-quot-into-amp-quot-then-using-SYMPUT-with-a/m-p/959368#M374304</guid>
      <dc:creator>Stu_SAS</dc:creator>
      <dc:date>2025-02-17T14:51:18Z</dc:date>
    </item>
    <item>
      <title>Re: Using PROC SQL &amp;quot;into;&amp;quot; , then using SYMPUT with a long macrovariable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-PROC-SQL-amp-quot-into-amp-quot-then-using-SYMPUT-with-a/m-p/959369#M374305</link>
      <description>&lt;P&gt;Hi Stu_SAS,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you, much appreciated that works well for what we're doing.&lt;/P&gt;&lt;P&gt;I've uploaded the datastep, it was based upon adding the new macrovariable to a simple table, which I"ve uploaded, too.&lt;/P&gt;&lt;P&gt;But that is not necessary given this nice solution you've provided.&lt;/P&gt;&lt;P&gt;Thanks again !&lt;/P&gt;&lt;P&gt;Robert&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data	sf.cit_T_1	;	set	sf.cit	;	
length	T_List	$5000.	;	
call symputx("T_List", &amp;amp;Cit_S_string);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 17 Feb 2025 14:59:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-PROC-SQL-amp-quot-into-amp-quot-then-using-SYMPUT-with-a/m-p/959369#M374305</guid>
      <dc:creator>rmacarthur</dc:creator>
      <dc:date>2025-02-17T14:59:16Z</dc:date>
    </item>
    <item>
      <title>Re: Using PROC SQL &amp;quot;into;&amp;quot; , then using SYMPUT with a long macrovariable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-PROC-SQL-amp-quot-into-amp-quot-then-using-SYMPUT-with-a/m-p/959373#M374308</link>
      <description>&lt;P&gt;I would go with:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data foo;
    string = symget("Cit_S_string");
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Mon, 17 Feb 2025 15:46:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-PROC-SQL-amp-quot-into-amp-quot-then-using-SYMPUT-with-a/m-p/959373#M374308</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2025-02-17T15:46:35Z</dc:date>
    </item>
    <item>
      <title>Re: Using PROC SQL &amp;quot;into;&amp;quot; , then using SYMPUT with a long macrovariable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-PROC-SQL-amp-quot-into-amp-quot-then-using-SYMPUT-with-a/m-p/959376#M374310</link>
      <description>&lt;P&gt;Yes, absolutely !&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Feb 2025 16:15:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-PROC-SQL-amp-quot-into-amp-quot-then-using-SYMPUT-with-a/m-p/959376#M374310</guid>
      <dc:creator>rmacarthur</dc:creator>
      <dc:date>2025-02-17T16:15:30Z</dc:date>
    </item>
    <item>
      <title>Re: Using PROC SQL &amp;quot;into;&amp;quot; , then using SYMPUT with a long macrovariable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-PROC-SQL-amp-quot-into-amp-quot-then-using-SYMPUT-with-a/m-p/959383#M374311</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/28361"&gt;@rmacarthur&lt;/a&gt;&amp;nbsp;wrote: ...&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;data	sf.cit_T_1	;	set	sf.cit	;	
length	T_List	$5000.	;	
call symputx("T_List", &amp;amp;Cit_S_string);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That explains why you got errors.&amp;nbsp; Not sure what text was put into CIT_S_STRING but you did use ; as the delimiter so the value is going to look something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;aaa;bbb;ccc&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So if you replace the reference to the macro variable with the text it contains you end up with a statement like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;call symputx("T_List", aaa;bbb;ccc);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which is not valid syntax.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But the whole data step is not very useful.&amp;nbsp; Even if you fix the code so that it passes an actual string to the CALL SYMPUTX() function the step is not really doing anything useful.&amp;nbsp; It will make&amp;nbsp;sf.cit_T_1 as an exact copy of sf.cit only with the addition of a empty variable with length of 5,000 bytes.&amp;nbsp; (Since you do not modify any of the variables in the data step.)&amp;nbsp; The CALL SYMPUTX() function will execute once for each observation read in.&amp;nbsp; But the value it writes to the macro variable T_LIST will always be the same since it does not depend on any variable in the data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To set a value to a variable in a data step use an assignment statement.&amp;nbsp; You could use the macro processor to generate a string literal in the assignment statement by adding double quote characters around the macro variable reference.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;T_List = "&amp;amp;Cit_S_string" ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That might have trouble if the value CIT_S_STRING includes double quote characters already.&amp;nbsp; So it would be safer to use the SYMGET() function instead.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;T_List = symget('Cit_S_string') ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also note that there is no need to include a period when specifying the length of the T_LIST variable.&amp;nbsp; Lengths of SAS variables are always integers, so there is no need for the decimal point.&amp;nbsp; Perhaps you are confusing the $nnn using in the LENGTH statement with a format or informat specification?&amp;nbsp; In SAS code you need to include a period in a format/informat specification so the SAS compiler can distinguish between a variable name reference and format or informat specification.&amp;nbsp; There is no need to worry about that in a LENGTH statement as you cannot include format or informat specifications there, just variable names and lengths.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And if the goal is a dataset variable and not a macro variable then skip the macro variable generation and just make the dataset variable directly.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data t_list;
  length t_list $5000 ;
  retain t_list;
  set sf.test end=eof;
  t_list = catx(';',t_list,cit_s);
  if eof;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now you can easily add that variable to your other dataset.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data sf.cit_T_1;
  set sf.cit ;
  if _n_=1 then set t_list;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;PS The reason your posted code looks so strange is you appear to have typed TAB characters instead of spaces into the code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Feb 2025 17:19:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-PROC-SQL-amp-quot-into-amp-quot-then-using-SYMPUT-with-a/m-p/959383#M374311</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-02-17T17:19:36Z</dc:date>
    </item>
    <item>
      <title>Re: Using PROC SQL &amp;quot;into;&amp;quot; , then using SYMPUT with a long macrovariable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-PROC-SQL-amp-quot-into-amp-quot-then-using-SYMPUT-with-a/m-p/959410#M374322</link>
      <description>&lt;P&gt;Hi Tom,&lt;/P&gt;&lt;P&gt;Thanks, I learned allot from your summary.&lt;/P&gt;&lt;P&gt;and yes I do type &amp;lt;tab&amp;gt; in my SAS code !&lt;/P&gt;&lt;P&gt;Helps things line up better, which helps me catch mistakes&lt;/P&gt;&lt;P&gt;and look for consistency.&lt;/P&gt;&lt;P&gt;Very much appreciated,&amp;nbsp;&lt;/P&gt;&lt;P&gt;R.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Feb 2025 20:45:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-PROC-SQL-amp-quot-into-amp-quot-then-using-SYMPUT-with-a/m-p/959410#M374322</guid>
      <dc:creator>rmacarthur</dc:creator>
      <dc:date>2025-02-17T20:45:59Z</dc:date>
    </item>
  </channel>
</rss>

