<?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: Add dataset-name as new variable and repeat for a large number of datasets in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Add-dataset-name-as-new-variable-and-repeat-for-a-large-number/m-p/333351#M62835</link>
    <description>&lt;P&gt;Again, thank you&amp;nbsp;&lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954" target="_blank"&gt;@Astounding&lt;/A&gt;&amp;nbsp;for your help. That solution you proposed I already tried, and it does unfortuntly not work. I solved it very very badly but at least I can continue. Since all files have almost the same name (what differs is the date), I made 31 single conversion for each day in the month:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data want_YYYY_MM_DD;&lt;BR /&gt;set have._&lt;SPAN&gt;YYYY_MM_DD&lt;/SPAN&gt; (rename=(TROUBLE_VARIABLE=TEMP));&lt;BR /&gt;&lt;SPAN&gt;TROUBLE_VARIABLE&lt;/SPAN&gt;&amp;nbsp;= put(TEMP, 7.);&lt;BR /&gt;drop TEMP;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Next by doing "find and replace" on the YYYY and MM numbers, I could repeat the procedure for every month and every year in my sample period. As said, this was very non-fancy, but it worked!&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 16 Feb 2017 12:27:21 GMT</pubDate>
    <dc:creator>MiniRadde</dc:creator>
    <dc:date>2017-02-16T12:27:21Z</dc:date>
    <item>
      <title>Add dataset-name as new variable and repeat for a large number of datasets</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Add-dataset-name-as-new-variable-and-repeat-for-a-large-number/m-p/330821#M62637</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am stuck on a procedure that I really need to automize,&amp;nbsp;but I am very new to writing own code in SAS.&lt;/P&gt;&lt;P&gt;My problem could be summarized as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;input &amp;gt; 500 datasets (named dataset_name) having X variables.&lt;/P&gt;&lt;P&gt;output = 1 dataset having X+1 variables ("+1" = "name" in dataset_name).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What this means is that I have a library that contains over 500 datasets that I'd like to consolidate. All files are named with the same prefix, followed by the date, e.g.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data_2017-01-06&lt;/P&gt;&lt;P&gt;data_2017-01-18&lt;/P&gt;&lt;P&gt;data_2017-02-08,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and so on. What I need to do is to create a new dataset containing all observations from all datasets, while I also need to be able to identify at which date the observation was made (i.e. the date-part of the dataset name). I would like to store only the YYYY-MM-DD part of the name as observations (preferably as characters).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there any friendly soul out there who could help me to solve this problem?&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2017 13:12:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Add-dataset-name-as-new-variable-and-repeat-for-a-large-number/m-p/330821#M62637</guid>
      <dc:creator>MiniRadde</dc:creator>
      <dc:date>2017-02-08T13:12:21Z</dc:date>
    </item>
    <item>
      <title>Re: Add dataset-name as new variable and repeat for a large number of datasets</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Add-dataset-name-as-new-variable-and-repeat-for-a-large-number/m-p/330826#M62639</link>
      <description>&lt;P&gt;SAS actually contains very helpful tools for this. &amp;nbsp;Assuming that you want all data set names that begin with data_2017 ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set lib.data_2017: indsname=complete_name;&lt;/P&gt;
&lt;P&gt;date_id = scan(complete_name, 2, '_');&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The colon in data_2017: gets you all data set names that begin with those characters. &amp;nbsp;INDSNAME= creates a variable holding the name of the incoming data set.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2017 13:23:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Add-dataset-name-as-new-variable-and-repeat-for-a-large-number/m-p/330826#M62639</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-02-08T13:23:01Z</dc:date>
    </item>
    <item>
      <title>Re: Add dataset-name as new variable and repeat for a large number of datasets</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Add-dataset-name-as-new-variable-and-repeat-for-a-large-number/m-p/330830#M62640</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;beat me to it. &amp;nbsp;I was just having to use this technique myself! &amp;nbsp;Here's what I did with my collection of daily data sets that have the name pattern "GA_DAILYyyyymmdd". &amp;nbsp;Use the colon operator to match the name pattern, and the INDSNAME= option to capture the input data set name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data consolidated;
  length source $ 32;
  set ga.ga_daily: indsname=in;
  source = in;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/7128iB9D0E01BFC2D2ACA/image-size/medium?v=1.0&amp;amp;px=-1" border="0" alt="indsname.png" title="indsname.png" /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2017 13:30:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Add-dataset-name-as-new-variable-and-repeat-for-a-large-number/m-p/330830#M62640</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2017-02-08T13:30:36Z</dc:date>
    </item>
    <item>
      <title>Re: Add dataset-name as new variable and repeat for a large number of datasets</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Add-dataset-name-as-new-variable-and-repeat-for-a-large-number/m-p/330834#M62641</link>
      <description>Hi ChrisHemedinger! Thank you so much for your help! The code worked almost perfect, the only thing was that it stored the entire file-name, but that is really a trifle. Thank you, and thank you again!</description>
      <pubDate>Wed, 08 Feb 2017 13:46:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Add-dataset-name-as-new-variable-and-repeat-for-a-large-number/m-p/330834#M62641</guid>
      <dc:creator>MiniRadde</dc:creator>
      <dc:date>2017-02-08T13:46:37Z</dc:date>
    </item>
    <item>
      <title>Re: Add dataset-name as new variable and repeat for a large number of datasets</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Add-dataset-name-as-new-variable-and-repeat-for-a-large-number/m-p/330835#M62642</link>
      <description>Hi Astounding! Waow, I really did not expect help that fast! Your code works PERFEKT! Thank you so much for your help, I could not have figured this out myself in time!</description>
      <pubDate>Wed, 08 Feb 2017 13:49:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Add-dataset-name-as-new-variable-and-repeat-for-a-large-number/m-p/330835#M62642</guid>
      <dc:creator>MiniRadde</dc:creator>
      <dc:date>2017-02-08T13:49:16Z</dc:date>
    </item>
    <item>
      <title>Re: Add dataset-name as new variable and repeat for a large number of datasets</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Add-dataset-name-as-new-variable-and-repeat-for-a-large-number/m-p/330839#M62643</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&lt;SPAN class="login-bold"&gt;&amp;nbsp;and&lt;/SPAN&gt; &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4"&gt;@ChrisHemedinger&lt;/a&gt;, I am forever grateful to your quick support!&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2017 13:53:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Add-dataset-name-as-new-variable-and-repeat-for-a-large-number/m-p/330839#M62643</guid>
      <dc:creator>MiniRadde</dc:creator>
      <dc:date>2017-02-08T13:53:22Z</dc:date>
    </item>
    <item>
      <title>Re: Add dataset-name as new variable and repeat for a large number of datasets</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Add-dataset-name-as-new-variable-and-repeat-for-a-large-number/m-p/332098#M62766</link>
      <description>&lt;P&gt;Hi again, and sorry for bothering about this topic again.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The solution worked fine as long as the dataset-formats were equal. When running over al my sets, I noticed that in some -not all- of my files there exists a variable X. Sometimes this one is defined as numeric and sometimes as character, resulting in an error:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Variable X has been defined as both character and numeric&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried to solve it using&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;set lib.data_2017: (rename=X) or&amp;nbsp;(drop=X), &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;and so on, but this won't work since the variable is not in all datasets. Any ideas on how to proceed?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2017 09:09:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Add-dataset-name-as-new-variable-and-repeat-for-a-large-number/m-p/332098#M62766</guid>
      <dc:creator>MiniRadde</dc:creator>
      <dc:date>2017-02-13T09:09:17Z</dc:date>
    </item>
    <item>
      <title>Re: Add dataset-name as new variable and repeat for a large number of datasets</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Add-dataset-name-as-new-variable-and-repeat-for-a-large-number/m-p/332373#M62775</link>
      <description>&lt;P&gt;There's only&amp;nbsp;one quick solution that I know of &amp;nbsp;... and I'm not 100% sure it would work. &amp;nbsp;It would only apply if X is the one and only variable name that begins with "X" in your data set(s). &amp;nbsp;In that case, you could try &lt;FONT face="courier new,courier"&gt;( drop=x: )&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If there are other variable names that begin with "X", however, this approach would drop those other variables as well. &amp;nbsp;More cumbersome methods are required.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If this does work, it might generate a warning.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regardless, the final solution will not be able to combine the data sets if a variable is character in one data set and numeric in another.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2017 21:56:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Add-dataset-name-as-new-variable-and-repeat-for-a-large-number/m-p/332373#M62775</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-02-13T21:56:00Z</dc:date>
    </item>
    <item>
      <title>Re: Add dataset-name as new variable and repeat for a large number of datasets</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Add-dataset-name-as-new-variable-and-repeat-for-a-large-number/m-p/333351#M62835</link>
      <description>&lt;P&gt;Again, thank you&amp;nbsp;&lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954" target="_blank"&gt;@Astounding&lt;/A&gt;&amp;nbsp;for your help. That solution you proposed I already tried, and it does unfortuntly not work. I solved it very very badly but at least I can continue. Since all files have almost the same name (what differs is the date), I made 31 single conversion for each day in the month:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data want_YYYY_MM_DD;&lt;BR /&gt;set have._&lt;SPAN&gt;YYYY_MM_DD&lt;/SPAN&gt; (rename=(TROUBLE_VARIABLE=TEMP));&lt;BR /&gt;&lt;SPAN&gt;TROUBLE_VARIABLE&lt;/SPAN&gt;&amp;nbsp;= put(TEMP, 7.);&lt;BR /&gt;drop TEMP;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Next by doing "find and replace" on the YYYY and MM numbers, I could repeat the procedure for every month and every year in my sample period. As said, this was very non-fancy, but it worked!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Feb 2017 12:27:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Add-dataset-name-as-new-variable-and-repeat-for-a-large-number/m-p/333351#M62835</guid>
      <dc:creator>MiniRadde</dc:creator>
      <dc:date>2017-02-16T12:27:21Z</dc:date>
    </item>
  </channel>
</rss>

