<?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: Find csv datasets with birthday or dob variables and create a report. Filenames have with space in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Find-csv-datasets-with-birthday-or-dob-variables-and-create-a/m-p/776376#M246907</link>
    <description>&lt;P&gt;I would go about this differently.&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Find files with a .csv extension. Might be simple or a little complex if you need to search multiple directories.&lt;/LI&gt;
&lt;LI&gt;Read the header line of each file&lt;/LI&gt;
&lt;LI&gt;Scan it for names indicating a date&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;I would not rely at all on the formats set by the guessing of PROC IMPORT.&lt;/P&gt;</description>
    <pubDate>Tue, 26 Oct 2021 06:44:20 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2021-10-26T06:44:20Z</dc:date>
    <item>
      <title>Find csv datasets with birthday or dob variables and create a report. Filenames have with space</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-csv-datasets-with-birthday-or-dob-variables-and-create-a/m-p/776302#M246858</link>
      <description>&lt;P&gt;Hi Community,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to see if there are variables in the dataset that have a birthday or dob information in them. The input datasets are in CSV and there are more than 100K files.&amp;nbsp; The following code seems fine if the input filename has no space or special character in it. However, there are many original filenames with space or special characters as the example below, fij k-1, so the code cannot work. I need help to tackle it as the original names in CSV don't allow to alter.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%Macro CSV(filename);&lt;BR /&gt;options obs=5;&lt;BR /&gt;options validvarname=any;&lt;BR /&gt;options validmemname=extend;&lt;BR /&gt;proc import out=&amp;amp;filename &lt;BR /&gt;datafile="&amp;amp;dir\&amp;amp;filename..csv"&lt;BR /&gt;dbms=csv;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table keep as&lt;BR /&gt;select memname, name ,format&lt;BR /&gt;from dictionary.columns &lt;BR /&gt;where libname='WORK' and &lt;BR /&gt;(&lt;BR /&gt;(index(upcase(name),'BIRTH')&amp;gt;0) or&lt;BR /&gt;(index(upcase(name),'DOB')&amp;gt;0))&lt;/P&gt;
&lt;P&gt;AND&lt;/P&gt;
&lt;P&gt;((index(format, 'MMDDYY')&amp;gt;0) or&lt;BR /&gt;(index(format, 'DATE')&amp;gt;0))&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;data list;&lt;BR /&gt;set keep;&lt;BR /&gt;Directoryname="&amp;amp;dir";&lt;BR /&gt;rename memname=Filename name=Variable;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;%Mend CSV;&lt;/P&gt;
&lt;P&gt;%let dir=C:\abc\ef g&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;%CSV(fij k-1)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Oct 2021 21:34:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-csv-datasets-with-birthday-or-dob-variables-and-create-a/m-p/776302#M246858</guid>
      <dc:creator>CHL0320</dc:creator>
      <dc:date>2021-10-25T21:34:14Z</dc:date>
    </item>
    <item>
      <title>Re: Find csv datasets with birthday or dob variables and create a report. Filenames have with space</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-csv-datasets-with-birthday-or-dob-variables-and-create-a/m-p/776310#M246862</link>
      <description>&lt;P&gt;Search the forum for reading lists of files using operating system tools such as the DIR (windows) or LS command (Unix/Linux) so that you have a complete path/filename as one variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Some :&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/macro-for-load-in-multiple-files-csv/m-p/763795" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/macro-for-load-in-multiple-files-csv/m-p/763795&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Help-merging-multiple-CSV-files-to-a-dataset/m-p/184804" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/Help-merging-multiple-CSV-files-to-a-dataset/m-p/184804&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or if there are some rules for building the names...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If all the files (or possibly even most) have the same structure there are ways to read them using wildcards in the names.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BTW:&lt;/P&gt;
&lt;P&gt;Doesn't work is awful vague.&lt;BR /&gt;&lt;BR /&gt;Are there errors in the log?: Post the code and log in a code box opened with the "&amp;lt;/&amp;gt;" to maintain formatting of error messages.&lt;BR /&gt;&lt;BR /&gt;No output? Post any log in a code box.&lt;BR /&gt;&lt;BR /&gt;Unexpected output? Provide input data in the form of data step code pasted into a code box, the actual results and the expected results. Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the "&amp;lt;/&amp;gt;" icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Typically debugging macros involves setting Options MPRINT; and possibly SYMBOLGEN and MLOGIC depending on the type of code generation failure you are having.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Oct 2021 22:11:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-csv-datasets-with-birthday-or-dob-variables-and-create-a/m-p/776310#M246862</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-10-25T22:11:34Z</dc:date>
    </item>
    <item>
      <title>Re: Find csv datasets with birthday or dob variables and create a report. Filenames have with space</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-csv-datasets-with-birthday-or-dob-variables-and-create-a/m-p/776315#M246866</link>
      <description>&lt;P&gt;I wouldn't bother with this portion:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;((index(format, 'MMDDYY')&amp;gt;0) or
(index(format, 'DATE')&amp;gt;0))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you're using PROC IMPORT to import the data it could be character or datetime because you're not specifying variable types. Do you only want SAS dates? If so, look at the FMTINFO() function instead to get all date formats.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/108652"&gt;@CHL0320&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi Community,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to see if there are variables in the dataset that have a birthday or dob information in them. The input datasets are in CSV and there are more than 100K files.&amp;nbsp; The following code seems fine if the input filename has no space or special character in it. However, there are many original filenames with space or special characters as the example below, fij k-1, so the code cannot work. I need help to tackle it as the original names in CSV don't allow to alter.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%Macro CSV(filename);&lt;BR /&gt;options obs=5;&lt;BR /&gt;options validvarname=any;&lt;BR /&gt;options validmemname=extend;&lt;BR /&gt;proc import out=&amp;amp;filename &lt;BR /&gt;datafile="&amp;amp;dir\&amp;amp;filename..csv"&lt;BR /&gt;dbms=csv;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table keep as&lt;BR /&gt;select memname, name ,format&lt;BR /&gt;from dictionary.columns &lt;BR /&gt;where libname='WORK' and &lt;BR /&gt;(&lt;BR /&gt;(index(upcase(name),'BIRTH')&amp;gt;0) or&lt;BR /&gt;(index(upcase(name),'DOB')&amp;gt;0))&lt;/P&gt;
&lt;P&gt;AND&lt;/P&gt;
&lt;P&gt;((index(format, 'MMDDYY')&amp;gt;0) or&lt;BR /&gt;(index(format, 'DATE')&amp;gt;0))&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;data list;&lt;BR /&gt;set keep;&lt;BR /&gt;Directoryname="&amp;amp;dir";&lt;BR /&gt;rename memname=Filename name=Variable;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;%Mend CSV;&lt;/P&gt;
&lt;P&gt;%let dir=C:\abc\ef g&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;%CSV(fij k-1)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Oct 2021 22:29:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-csv-datasets-with-birthday-or-dob-variables-and-create-a/m-p/776315#M246866</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-10-25T22:29:20Z</dc:date>
    </item>
    <item>
      <title>Re: Find csv datasets with birthday or dob variables and create a report. Filenames have with space</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-csv-datasets-with-birthday-or-dob-variables-and-create-a/m-p/776376#M246907</link>
      <description>&lt;P&gt;I would go about this differently.&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Find files with a .csv extension. Might be simple or a little complex if you need to search multiple directories.&lt;/LI&gt;
&lt;LI&gt;Read the header line of each file&lt;/LI&gt;
&lt;LI&gt;Scan it for names indicating a date&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;I would not rely at all on the formats set by the guessing of PROC IMPORT.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Oct 2021 06:44:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-csv-datasets-with-birthday-or-dob-variables-and-create-a/m-p/776376#M246907</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-10-26T06:44:20Z</dc:date>
    </item>
  </channel>
</rss>

