<?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: Want to convert csv files to sas7bdat from folder in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Want-to-convert-csv-files-to-sas7bdat-from-folder/m-p/793820#M254475</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/240711"&gt;@noda6003&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I want to convert all csv files in a folder to sas7bdat and have the names same as it is in csv file, I found a program but it doesnt work. any help on it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro drive(dir,ext); 
   %local cnt filrf rc did memcnt name;

   %let cnt=0;
   %let filrf=mydir;

   %let rc=%sysfunc(filename(filrf,&amp;amp;dir));
   %let did=%sysfunc(dopen(&amp;amp;filrf));

   %if &amp;amp;did ne 0 %then %do;
      %let memcnt=%sysfunc(dnum(&amp;amp;did));
      %do i=1 %to &amp;amp;memcnt;
         %let name=%qscan(%qsysfunc(dread(&amp;amp;did,&amp;amp;i)),-1,.);
         %if %qupcase(%qsysfunc(dread(&amp;amp;did,&amp;amp;i))) ne %qupcase(&amp;amp;name) %then %do;
            %if %superq(ext) = %superq(name) %then %do;
               %let cnt=%eval(&amp;amp;cnt+1);
               %put %qsysfunc(dread(&amp;amp;did,&amp;amp;i));
               proc import datafile="&amp;amp;dir\%qsysfunc(dread(&amp;amp;did,&amp;amp;i))" out=dsn&amp;amp;cnt 
                  dbms=csv replace;
               run;
            %end;
         %end;
       %end;
    %end;
  %else %put &amp;amp;dir cannot be opened.;

  %let rc=%sysfunc(dclose(&amp;amp;did));
%mend drive;

%drive(C:/let,csv);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;How can i replace them with dataset as it is in csv and place in same folder as csv&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Names of what? The SAS data set? Variables? Both have rules in SAS and may not be possible. SAS datasets and variable names are limited in the number of characters allowed: 32.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also:&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;</description>
    <pubDate>Tue, 01 Feb 2022 15:14:08 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2022-02-01T15:14:08Z</dc:date>
    <item>
      <title>Want to convert csv files to sas7bdat from folder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Want-to-convert-csv-files-to-sas7bdat-from-folder/m-p/793712#M254429</link>
      <description>&lt;P&gt;I want to convert all csv files in a folder to sas7bdat and have the names same as it is in csv file, I found a program but it doesnt work. any help on it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro drive(dir,ext); 
   %local cnt filrf rc did memcnt name;

   %let cnt=0;
   %let filrf=mydir;

   %let rc=%sysfunc(filename(filrf,&amp;amp;dir));
   %let did=%sysfunc(dopen(&amp;amp;filrf));

   %if &amp;amp;did ne 0 %then %do;
      %let memcnt=%sysfunc(dnum(&amp;amp;did));
      %do i=1 %to &amp;amp;memcnt;
         %let name=%qscan(%qsysfunc(dread(&amp;amp;did,&amp;amp;i)),-1,.);
         %if %qupcase(%qsysfunc(dread(&amp;amp;did,&amp;amp;i))) ne %qupcase(&amp;amp;name) %then %do;
            %if %superq(ext) = %superq(name) %then %do;
               %let cnt=%eval(&amp;amp;cnt+1);
               %put %qsysfunc(dread(&amp;amp;did,&amp;amp;i));
               proc import datafile="&amp;amp;dir\%qsysfunc(dread(&amp;amp;did,&amp;amp;i))" out=dsn&amp;amp;cnt 
                  dbms=csv replace;
               run;
            %end;
         %end;
       %end;
    %end;
  %else %put &amp;amp;dir cannot be opened.;

  %let rc=%sysfunc(dclose(&amp;amp;did));
%mend drive;

%drive(C:/let,csv);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;How can i replace them with dataset as it is in csv and place in same folder as csv&lt;/P&gt;</description>
      <pubDate>Tue, 01 Feb 2022 10:02:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Want-to-convert-csv-files-to-sas7bdat-from-folder/m-p/793712#M254429</guid>
      <dc:creator>noda6003</dc:creator>
      <dc:date>2022-02-01T10:02:47Z</dc:date>
    </item>
    <item>
      <title>Re: Want to convert csv files to sas7bdat from folder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Want-to-convert-csv-files-to-sas7bdat-from-folder/m-p/793714#M254431</link>
      <description>&lt;P&gt;You have to specify a SAS libref in the out= option that points to the same location as where your Excel files resides.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Feb 2022 10:21:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Want-to-convert-csv-files-to-sas7bdat-from-folder/m-p/793714#M254431</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2022-02-01T10:21:49Z</dc:date>
    </item>
    <item>
      <title>Re: Want to convert csv files to sas7bdat from folder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Want-to-convert-csv-files-to-sas7bdat-from-folder/m-p/793737#M254446</link>
      <description>&lt;P&gt;I would recommend against having non-SAS files in a directory that is used as a SAS library. Instead do a tree like&lt;/P&gt;
&lt;PRE&gt;- import
- - saslib
- - excel_files&lt;/PRE&gt;
&lt;P&gt;Put the spreadsheets into excel_files, and run the LIBNAME for saslib.&lt;/P&gt;
&lt;P&gt;You can still move/copy/delete everything through the parent directory import.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Feb 2022 12:11:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Want-to-convert-csv-files-to-sas7bdat-from-folder/m-p/793737#M254446</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-02-01T12:11:09Z</dc:date>
    </item>
    <item>
      <title>Re: Want to convert csv files to sas7bdat from folder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Want-to-convert-csv-files-to-sas7bdat-from-folder/m-p/793769#M254462</link>
      <description>&lt;P&gt;I have created libname but not sure how to make same dataset names as in csv in out=&lt;/P&gt;</description>
      <pubDate>Tue, 01 Feb 2022 14:22:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Want-to-convert-csv-files-to-sas7bdat-from-folder/m-p/793769#M254462</guid>
      <dc:creator>noda6003</dc:creator>
      <dc:date>2022-02-01T14:22:27Z</dc:date>
    </item>
    <item>
      <title>Re: Want to convert csv files to sas7bdat from folder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Want-to-convert-csv-files-to-sas7bdat-from-folder/m-p/793789#M254466</link>
      <description>&lt;P&gt;To direct the output of the IMPORT procedure to a library other than WORK, you need to tell it so in the OUT= option of the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/n18jyszn33umngn14czw2qfw7thc.htm" target="_blank" rel="noopener"&gt;PROC IMPORT&lt;/A&gt; statement and use a two-level name for the dataset there.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Feb 2022 14:51:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Want-to-convert-csv-files-to-sas7bdat-from-folder/m-p/793789#M254466</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-02-01T14:51:04Z</dc:date>
    </item>
    <item>
      <title>Re: Want to convert csv files to sas7bdat from folder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Want-to-convert-csv-files-to-sas7bdat-from-folder/m-p/793806#M254469</link>
      <description>&lt;P&gt;sorry for asking again, but i have multiple csv files so i am not sure how to get same names of csv to sas7bdat&lt;/P&gt;</description>
      <pubDate>Tue, 01 Feb 2022 14:59:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Want-to-convert-csv-files-to-sas7bdat-from-folder/m-p/793806#M254469</guid>
      <dc:creator>noda6003</dc:creator>
      <dc:date>2022-02-01T14:59:38Z</dc:date>
    </item>
    <item>
      <title>Re: Want to convert csv files to sas7bdat from folder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Want-to-convert-csv-files-to-sas7bdat-from-folder/m-p/793819#M254474</link>
      <description>&lt;P&gt;See the changes/additions in this code piece:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;      %do i=1 %to &amp;amp;memcnt;
         %let name=%qscan(%qsysfunc(dread(&amp;amp;did,&amp;amp;i)),-1,.);
         %if %qupcase(%qsysfunc(dread(&amp;amp;did,&amp;amp;i))) ne %qupcase(&amp;amp;name) %then %do;
            %if %superq(ext) = %superq(name) %then %do;
               %let fname = %scan(%qsysfunc(dread(&amp;amp;did,&amp;amp;i)),1,.);
               %put %qsysfunc(dread(&amp;amp;did,&amp;amp;i));
               proc import
                 datafile="&amp;amp;dir\%qsysfunc(dread(&amp;amp;did,&amp;amp;i))"
                 out=libname.&amp;amp;fname. 
                 dbms=csv
                 replace
               ;
               run;
            %end;
         %end;
       %end;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It assumes that there will be only one dot in the filename, separating the sheet name from the file extension (otherwise the name would be invalid for a dataset anyway). Replace "libname" with the name of your intended target library. Macro variable cnt is no longer used.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Feb 2022 15:13:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Want-to-convert-csv-files-to-sas7bdat-from-folder/m-p/793819#M254474</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-02-01T15:13:39Z</dc:date>
    </item>
    <item>
      <title>Re: Want to convert csv files to sas7bdat from folder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Want-to-convert-csv-files-to-sas7bdat-from-folder/m-p/793820#M254475</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/240711"&gt;@noda6003&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I want to convert all csv files in a folder to sas7bdat and have the names same as it is in csv file, I found a program but it doesnt work. any help on it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro drive(dir,ext); 
   %local cnt filrf rc did memcnt name;

   %let cnt=0;
   %let filrf=mydir;

   %let rc=%sysfunc(filename(filrf,&amp;amp;dir));
   %let did=%sysfunc(dopen(&amp;amp;filrf));

   %if &amp;amp;did ne 0 %then %do;
      %let memcnt=%sysfunc(dnum(&amp;amp;did));
      %do i=1 %to &amp;amp;memcnt;
         %let name=%qscan(%qsysfunc(dread(&amp;amp;did,&amp;amp;i)),-1,.);
         %if %qupcase(%qsysfunc(dread(&amp;amp;did,&amp;amp;i))) ne %qupcase(&amp;amp;name) %then %do;
            %if %superq(ext) = %superq(name) %then %do;
               %let cnt=%eval(&amp;amp;cnt+1);
               %put %qsysfunc(dread(&amp;amp;did,&amp;amp;i));
               proc import datafile="&amp;amp;dir\%qsysfunc(dread(&amp;amp;did,&amp;amp;i))" out=dsn&amp;amp;cnt 
                  dbms=csv replace;
               run;
            %end;
         %end;
       %end;
    %end;
  %else %put &amp;amp;dir cannot be opened.;

  %let rc=%sysfunc(dclose(&amp;amp;did));
%mend drive;

%drive(C:/let,csv);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;How can i replace them with dataset as it is in csv and place in same folder as csv&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Names of what? The SAS data set? Variables? Both have rules in SAS and may not be possible. SAS datasets and variable names are limited in the number of characters allowed: 32.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also:&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;</description>
      <pubDate>Tue, 01 Feb 2022 15:14:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Want-to-convert-csv-files-to-sas7bdat-from-folder/m-p/793820#M254475</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-02-01T15:14:08Z</dc:date>
    </item>
    <item>
      <title>Re: Want to convert csv files to sas7bdat from folder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Want-to-convert-csv-files-to-sas7bdat-from-folder/m-p/793830#M254479</link>
      <description>&lt;P&gt;What your rules for "&lt;SPAN&gt;have the names same as it is in csv file"?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Do you want to include the .csv in the dataset names?&amp;nbsp; SAS names do not normally allow periods.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Let's assume you meant you wanted to remove the .csv from the end of the name.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;What about names with other invalid characters, like hyphens or spaces?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;What about names that start with a digit?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;To remove the .csv once you have found it is simple.&amp;nbsp; If you are positive there is only one period in the name just use SCAN() again with 1 instead of -1 as the index.&amp;nbsp; Otherwise use SUBSTR() to to remove the last 4 characters (the length of &amp;amp;ext plus 1).&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Feb 2022 15:31:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Want-to-convert-csv-files-to-sas7bdat-from-folder/m-p/793830#M254479</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-02-01T15:31:03Z</dc:date>
    </item>
  </channel>
</rss>

