<?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: Concatenate a list to a data table in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-a-list-to-a-data-table/m-p/918019#M361630</link>
    <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/458617"&gt;@LuGa&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can assign only one value at a time: the value for the observation that is currently being processed in the DATA step. So you need to split the list into single values. This can be done with the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p0jshdjy2z9zdzn1h7k90u99lyq6.htm" target="_blank" rel="noopener"&gt;SCAN function&lt;/A&gt;:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set data;
col_2=input(scan("&amp;amp;list",_n_,' '),32.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or you can supply the list as the list of initial values of an &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/p08do6szetrxe2n136ush727sbuo.htm" target="_blank" rel="noopener"&gt;array&lt;/A&gt;:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set data;
array t[%sysfunc(countw(&amp;amp;list,%str( )))] _temporary_ (&amp;amp;list);
col_2=t[_n_];
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or read from the list with an &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/n0oaql83drile0n141pdacojq97s.htm" target="_blank" rel="noopener"&gt;INPUT statement&lt;/A&gt;:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set data;
input @;
_infile_ = "&amp;amp;list";
input col_2 @@;
cards;
-
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But the best approach might be to retrieve the values from where they resided before someone put them into a macro variable.&lt;/P&gt;</description>
    <pubDate>Tue, 27 Feb 2024 11:21:53 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2024-02-27T11:21:53Z</dc:date>
    <item>
      <title>Concatenate a list to a data table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-a-list-to-a-data-table/m-p/918007#M361621</link>
      <description>&lt;P&gt;Dear all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a list with values:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;%let list= 1 2 3 4 5 6 7 8;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a data table:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data data;
input col_1;
datalines;
8
7
6
5
4
3
2
1
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How to concatenate the list as a new column to the table?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is what I tried, which failed with the following error:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;3234  data data;
3235  set data;
3236  col_2 = &amp;amp;list.;
SYMBOLGEN:  Macro variable LIST resolves to 1 2 3 4 5 6 7 8
NOTE: Line generated by the macro variable "LIST".
1      1 2 3 4 5 6 7 8
         -
         388
         76
ERROR 388-185: Expecting an arithmetic operator.

ERROR 76-322: Syntax error, statement will be ignored.

3237  run;

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.DATA may be incomplete.  When this step was stopped there were 0 observations and 2 variables.
WARNING: Data set WORK.DATA was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks in advance&amp;nbsp;&lt;/P&gt;&lt;P&gt;Lukas&lt;/P&gt;</description>
      <pubDate>Tue, 27 Feb 2024 08:57:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenate-a-list-to-a-data-table/m-p/918007#M361621</guid>
      <dc:creator>LuGa</dc:creator>
      <dc:date>2024-02-27T08:57:08Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate a list to a data table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-a-list-to-a-data-table/m-p/918019#M361630</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/458617"&gt;@LuGa&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can assign only one value at a time: the value for the observation that is currently being processed in the DATA step. So you need to split the list into single values. This can be done with the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p0jshdjy2z9zdzn1h7k90u99lyq6.htm" target="_blank" rel="noopener"&gt;SCAN function&lt;/A&gt;:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set data;
col_2=input(scan("&amp;amp;list",_n_,' '),32.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or you can supply the list as the list of initial values of an &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/p08do6szetrxe2n136ush727sbuo.htm" target="_blank" rel="noopener"&gt;array&lt;/A&gt;:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set data;
array t[%sysfunc(countw(&amp;amp;list,%str( )))] _temporary_ (&amp;amp;list);
col_2=t[_n_];
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or read from the list with an &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/n0oaql83drile0n141pdacojq97s.htm" target="_blank" rel="noopener"&gt;INPUT statement&lt;/A&gt;:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set data;
input @;
_infile_ = "&amp;amp;list";
input col_2 @@;
cards;
-
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But the best approach might be to retrieve the values from where they resided before someone put them into a macro variable.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Feb 2024 11:21:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenate-a-list-to-a-data-table/m-p/918019#M361630</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2024-02-27T11:21:53Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate a list to a data table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-a-list-to-a-data-table/m-p/918023#M361632</link>
      <description>&lt;P&gt;Hello FreelanceReinh,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thank you. All of your suggestions work.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the meantime I created a quick and dirty workaround, which is by far not that elegant as your solutions.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data to_concat;
	
	length col_2 3;

    do i = 1 to countw("&amp;amp;list.", " ");
        col_2 = input(scan("&amp;amp;list.", i, " "), best32.);

        output;
    end;

	drop i;

run;

data want;
merge data to_concat;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks and all the best&amp;nbsp;&lt;/P&gt;&lt;P&gt;Lukas&lt;/P&gt;</description>
      <pubDate>Tue, 27 Feb 2024 12:31:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenate-a-list-to-a-data-table/m-p/918023#M361632</guid>
      <dc:creator>LuGa</dc:creator>
      <dc:date>2024-02-27T12:31:41Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate a list to a data table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-a-list-to-a-data-table/m-p/918030#M361639</link>
      <description>&lt;P&gt;Your code looks fine.&amp;nbsp; Two points.&lt;/P&gt;
&lt;P&gt;1) It is rarely worth it to set the storage length for numeric variables to anything other than the full 8 bytes needed to store the 64-bit binary floating point values SAS uses for numbers.&lt;/P&gt;
&lt;P&gt;2) BEST is the name of a FORMAT.&amp;nbsp; Don't use it as the name of an INFORMAT.&amp;nbsp; If you do it will cause others to get confused and wonder why you are using a FORMAT where an INFORMAT is needed.&amp;nbsp; And SAS will just use the normal informat anyway so you also typed four more characters into your program than you needed.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Feb 2024 14:34:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenate-a-list-to-a-data-table/m-p/918030#M361639</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-02-27T14:34:15Z</dc:date>
    </item>
  </channel>
</rss>

