<?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: How do I create a new column per dataset when concatenating multiple datasets? in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-do-I-create-a-new-column-per-dataset-when-concatenating/m-p/737280#M38709</link>
    <description>&lt;P&gt;Use the INDSNAME= option of the SET statement.&lt;/P&gt;
&lt;P&gt;This is used to name a (temporary) variable that will be populated with the name of the dataset that contributed this observation.&amp;nbsp; To add a permanent variable copy or transform the value into another variable. It kind of looks like the names have a month embedded in them.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data cues;
  length dsname $41 ;
  set
    cue_201603 (keep= id cue5 cue8  where=(ID IN (&amp;amp;c1.)))
    cue_201604 (keep= id cue5 cue8  where=(ID IN (&amp;amp;c1.)))
    cue_201605 (keep= id cue5 cue8  where=(ID IN (&amp;amp;c1.)))
    indsname=dsname
  ;
  month = input(scan(dsname,2,'_.'),yymmn6.);
  format month yymmn6. ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 27 Apr 2021 14:06:44 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-04-27T14:06:44Z</dc:date>
    <item>
      <title>How do I create a new column per dataset when concatenating multiple datasets?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-do-I-create-a-new-column-per-dataset-when-concatenating/m-p/737233#M38702</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using SAS Enterprise Guide 7.1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am concatenating multiple datasets together, however there isn't a date in any of the datasets, only the title. Is there a way to create a new column per dataset that I am&amp;nbsp;concatenating?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My current code without the extra columns is (for visibility I've kept just 3 months that I actually need):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data cues;
set
cue_201603 (keep= id cue5 cue8  where=(ID IN (&amp;amp;c1.)));
cue_201604 (keep= id cue5 cue8  where=(ID IN (&amp;amp;c1.)));
cue_201605 (keep= id cue5 cue8  where=(ID IN (&amp;amp;c1.)));
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I was hoping there was a way to create a column called month per dataset and have it output 201603, 201604 and 201605, so that it is all under the same column.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I also only want to select certain columns to speed it up, so would like to keep the keep statement, and also the where statement, to only select the specific ids in a macro variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can this be done?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Tue, 27 Apr 2021 12:22:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-do-I-create-a-new-column-per-dataset-when-concatenating/m-p/737233#M38702</guid>
      <dc:creator>_SASEG_</dc:creator>
      <dc:date>2021-04-27T12:22:25Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a new column per dataset when concatenating multiple datasets?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-do-I-create-a-new-column-per-dataset-when-concatenating/m-p/737280#M38709</link>
      <description>&lt;P&gt;Use the INDSNAME= option of the SET statement.&lt;/P&gt;
&lt;P&gt;This is used to name a (temporary) variable that will be populated with the name of the dataset that contributed this observation.&amp;nbsp; To add a permanent variable copy or transform the value into another variable. It kind of looks like the names have a month embedded in them.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data cues;
  length dsname $41 ;
  set
    cue_201603 (keep= id cue5 cue8  where=(ID IN (&amp;amp;c1.)))
    cue_201604 (keep= id cue5 cue8  where=(ID IN (&amp;amp;c1.)))
    cue_201605 (keep= id cue5 cue8  where=(ID IN (&amp;amp;c1.)))
    indsname=dsname
  ;
  month = input(scan(dsname,2,'_.'),yymmn6.);
  format month yymmn6. ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Apr 2021 14:06:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-do-I-create-a-new-column-per-dataset-when-concatenating/m-p/737280#M38709</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-04-27T14:06:44Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a new column per dataset when concatenating multiple datasets?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-do-I-create-a-new-column-per-dataset-when-concatenating/m-p/737388#M38725</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;! Yes, the date is embedded into the file. It worked perfectly!&lt;/P&gt;</description>
      <pubDate>Tue, 27 Apr 2021 19:23:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-do-I-create-a-new-column-per-dataset-when-concatenating/m-p/737388#M38725</guid>
      <dc:creator>_SASEG_</dc:creator>
      <dc:date>2021-04-27T19:23:33Z</dc:date>
    </item>
  </channel>
</rss>

