<?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: Batch reading text files with special characters the variable names in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Batch-reading-text-files-with-special-characters-the-variable/m-p/104819#M21849</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sound more like you have a character encoding issue that is preventing you from reading the source file.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you want to use the strings as variable NAMES then they will have to match SAS naming conventions for variable names. Names should consist only of letters, digits and underscore and cannot start with a digit.&amp;nbsp; Perhaps you should use the values as LABELS for your variables instead of NAMES?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can circumvent some of this by setting the option VALIDVARNAME to ANY. Then you can create name literals from your character variables.&amp;nbsp; Here is an example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;options validvarname=any;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;data x;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; "This is 'nuts', no?"n = 10;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt; line-height: 1.5em;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So here is a data step to create name literals and store them in global macro variables V1 to Vxxx from dataset variables X1 to Xxxx.&amp;nbsp; Note that you do not need macro logic to do this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em; font-family: 'courier new', courier;"&gt;data _null_;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; set var_names;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp; array names X: ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp; do i=1 to dim(names);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; call symputx( cats('V',i) , quote(trim(names(i)))||'n' , 'G' ) ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 12 Jun 2013 23:32:55 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2013-06-12T23:32:55Z</dc:date>
    <item>
      <title>Batch reading text files with special characters the variable names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Batch-reading-text-files-with-special-characters-the-variable/m-p/104816#M21846</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am trying to adapt code from the paper "A macro for reading multiple text files" by Debbie Miller to my own data.&amp;nbsp; The macro reads all the text files in a given folder, reads the variables and designates them as headers, then reads in all the data from all the text files into a single file. The result is a single SAS file containing all the headers and data contained in the target folder's text files. The issue I have is that some of the variable names in my text file's headers contain special characters (?, ', etc.). These cause the macro to fail. I would like to know if there is any way to make SAS read these special characters just as normal text (or, worst case, to delete them). So far I have tried the options validvarname=any; and compressing out the special characters, to no avail (although I assume I am just using them wrong). Here are the paper and code segments I believe to be relevant:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;After the name of the next file to be read has been retrieved, the names of the variables are read from the first line of the text file. In this macro, it is necessary to know the maximum number of variables possible in any text file. Here the maximum number is 17. The variable names are then stored as variables X1-X17 in the data set VAR_NAMES. Since at this point I only want to read the names of the variables, which are located in the first line of the input text file, I specify the option OBS=1 in the INFILE statement. This option tells SAS the number of the last record in the input file that you want to read. The MISSOVER option prevents SAS from automatically going to the next line if it doesn't find values for all of the variables. If fewer than 17 variables are read, the remaining variables are set to missing. The resulting data set contains only 1 record, with 17 text variables that contain the names of the variables in the input file that will be read next.&lt;/P&gt;&lt;P&gt;%macro fileread;&lt;/P&gt;&lt;P&gt;%do j=1 %to &amp;amp;num_files;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;set file_list;&lt;/P&gt;&lt;P&gt;if _n_=&amp;amp;j;&lt;/P&gt;&lt;P&gt;call symput ('filein',fname);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;data var_names;&lt;/P&gt;&lt;P&gt;length x1-x17 $12;&lt;/P&gt;&lt;P&gt;infile "d:\requests\miller\testfiles\&amp;amp;filein" obs=1 missover;&lt;/P&gt;&lt;P&gt;input (x1-x17) ($) ;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;A new macro called varnames that is nested inside the main macro, fileread, is then used to store the variable names to macro variables. The names are stored in macro variables V1 through V17. This is done by using a DATA _NULL_ step inside a do-loop that executes 17 times. A CALL SYMPUT statement is used to store the names to the macro variables. The GLOBAL statement is necessary so that the 17 macro variables will be available for use outside of the varnames macro.&lt;/P&gt;&lt;P&gt;%macro varnames;&lt;/P&gt;&lt;P&gt;%do i=1 %to 17;&lt;/P&gt;&lt;P&gt;%global v&amp;amp;i;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;set var_names;&lt;/P&gt;&lt;P&gt;call symput("v&amp;amp;i",trim(x&amp;amp;i));&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%mend varnames;&lt;/P&gt;&lt;P&gt;%varnames;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Jun 2013 22:29:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Batch-reading-text-files-with-special-characters-the-variable/m-p/104816#M21846</guid>
      <dc:creator>charles_pignon1</dc:creator>
      <dc:date>2013-06-12T22:29:18Z</dc:date>
    </item>
    <item>
      <title>Re: Batch reading text files with special characters the variable names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Batch-reading-text-files-with-special-characters-the-variable/m-p/104817#M21847</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Why are you using macro variables at all?&amp;nbsp; Why would you put the variable names into macro variables if you already have them in a dataset?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also look at the FILEVAR option on the INFILE statement so that you can also eliminate use macro variables to pass the file names.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Jun 2013 22:50:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Batch-reading-text-files-with-special-characters-the-variable/m-p/104817#M21847</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-06-12T22:50:49Z</dc:date>
    </item>
    <item>
      <title>Re: Batch reading text files with special characters the variable names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Batch-reading-text-files-with-special-characters-the-variable/m-p/104818#M21848</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the quick response! So, the variables are stored as macro variables and then combined with the data from the text files. This then puts the variable names as headers, under which the corresponding values are then stored.&lt;/P&gt;&lt;P&gt;This isn't even the issue at this point, however: I can't put the variable names into a dataset (var_names) because they contain special characters that SAS won't read. I tested the program by creating some test .txt files with only alphanumeric characters; it worked fine, but adding a single ' or ? character to one of the variables in the .txt files causes the macro to fail. It does not create the dataset var_names or perform any of the subsequent operations.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Jun 2013 23:03:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Batch-reading-text-files-with-special-characters-the-variable/m-p/104818#M21848</guid>
      <dc:creator>charles_pignon1</dc:creator>
      <dc:date>2013-06-12T23:03:40Z</dc:date>
    </item>
    <item>
      <title>Re: Batch reading text files with special characters the variable names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Batch-reading-text-files-with-special-characters-the-variable/m-p/104819#M21849</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sound more like you have a character encoding issue that is preventing you from reading the source file.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you want to use the strings as variable NAMES then they will have to match SAS naming conventions for variable names. Names should consist only of letters, digits and underscore and cannot start with a digit.&amp;nbsp; Perhaps you should use the values as LABELS for your variables instead of NAMES?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can circumvent some of this by setting the option VALIDVARNAME to ANY. Then you can create name literals from your character variables.&amp;nbsp; Here is an example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;options validvarname=any;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;data x;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; "This is 'nuts', no?"n = 10;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt; line-height: 1.5em;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So here is a data step to create name literals and store them in global macro variables V1 to Vxxx from dataset variables X1 to Xxxx.&amp;nbsp; Note that you do not need macro logic to do this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em; font-family: 'courier new', courier;"&gt;data _null_;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; set var_names;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp; array names X: ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp; do i=1 to dim(names);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; call symputx( cats('V',i) , quote(trim(names(i)))||'n' , 'G' ) ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Jun 2013 23:32:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Batch-reading-text-files-with-special-characters-the-variable/m-p/104819#M21849</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-06-12T23:32:55Z</dc:date>
    </item>
    <item>
      <title>Re: Batch reading text files with special characters the variable names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Batch-reading-text-files-with-special-characters-the-variable/m-p/104820#M21850</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Read in the file and look at what characters are actually there.&amp;nbsp; Perhaps you are trying to read a file that is not text at all?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp; infile ...... ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input;&lt;/P&gt;&lt;P&gt;&amp;nbsp; list;&lt;/P&gt;&lt;P&gt;&amp;nbsp; stop;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Jun 2013 23:55:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Batch-reading-text-files-with-special-characters-the-variable/m-p/104820#M21850</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-06-12T23:55:17Z</dc:date>
    </item>
    <item>
      <title>Re: Batch reading text files with special characters the variable names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Batch-reading-text-files-with-special-characters-the-variable/m-p/104821#M21851</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;I had already tried the validvarname=any, inserting it like this:&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;options validvarname=any;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;data var_names;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;length x1-x17 $12;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;infile "d:\requests\miller\testfiles\&amp;amp;filein" obs=1 missover;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;input (x1-x17) ($) ;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;run;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;That didn't work. I think your proposed data_null_ step would work if I was manually entering the variable names, however what I am actually trying to do is retrieve them from the .txt file. So (and I could be wrong) I &lt;EM&gt;think&lt;/EM&gt; that the problem is occurring either in the infile or in the input steps of the code I copied here. SAS never gets the chance to turn the data into variables,because it is not even able to read the data from the text file. I do think you're right therefore in that it's a character encoding issue, but I don't know how/where in the code to fix it.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Jun 2013 00:03:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Batch-reading-text-files-with-special-characters-the-variable/m-p/104821#M21851</guid>
      <dc:creator>charles_pignon1</dc:creator>
      <dc:date>2013-06-13T00:03:34Z</dc:date>
    </item>
    <item>
      <title>Re: Batch reading text files with special characters the variable names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Batch-reading-text-files-with-special-characters-the-variable/m-p/104822#M21852</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I created a text file specifically to test this, the first line has written, in tab delimited, a'?&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; b&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; c&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; d (etc.) and the second line is 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4. Note the '? in the first "variable name": when I remove them from the text file, the macro works just fine, and outputs one file (var_name) that looks like this:&lt;/P&gt;&lt;P&gt;v1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; v2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; v3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; v4&lt;/P&gt;&lt;P&gt;a&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; b&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; c&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; d&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The next step of the macro reads and adds in the data, creating another file (data_all) that looks like this:&lt;/P&gt;&lt;P&gt;a&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; b&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; c&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; d&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Where a b c d are the variable names and 1 2 3 4 is the data. However adding special characters to the first line in the text file makes it illegible to SAS&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Jun 2013 00:09:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Batch-reading-text-files-with-special-characters-the-variable/m-p/104822#M21852</guid>
      <dc:creator>charles_pignon1</dc:creator>
      <dc:date>2013-06-13T00:09:39Z</dc:date>
    </item>
    <item>
      <title>Re: Batch reading text files with special characters the variable names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Batch-reading-text-files-with-special-characters-the-variable/m-p/104823#M21853</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Why not let SAS convert the names for you?&lt;/P&gt;&lt;P&gt;Read the data into a tall format with NAME/VALUE pairs and pass it through PROC TRANSPOSE.&amp;nbsp; SAS will convert the values to valid names. In your example the first variable becomes A__ where underscores have replaced the quote and question mark.&lt;/P&gt;&lt;P&gt;This one eliminates the 17 column assumption and instead assumes that the columns stop when there are no more names. So you cannot have a gap in the column names in the source file.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Again no need for macro variables or macro logic.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;filename datafile "....";&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;data names ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; infile datafile dsd dlm='09'x truncover obs=1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; length name $32 ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; do until(name=' ');&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; input name @;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if name^=' ' then output;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;data tall ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; infile datafile dsd dlm='09'x truncover firstobs=2;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; row+1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; do col=1 to ncols;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set names point=col nobs=ncols;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; input value @;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;proc transpose data=tall out=wide;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; by row;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; var value;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; id name;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Jun 2013 01:20:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Batch-reading-text-files-with-special-characters-the-variable/m-p/104823#M21853</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-06-13T01:20:59Z</dc:date>
    </item>
    <item>
      <title>Re: Batch reading text files with special characters the variable names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Batch-reading-text-files-with-special-characters-the-variable/m-p/104824#M21854</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It almost works! This code did just what I wanted (even when special characters were in the text file), but only for one text file in the folder. Is there any way to now process all the text files in the folder and compile them into one dataset? I believe this was the purpose of the macro I was originally using.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Jun 2013 17:47:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Batch-reading-text-files-with-special-characters-the-variable/m-p/104824#M21854</guid>
      <dc:creator>charles_pignon1</dc:creator>
      <dc:date>2013-06-13T17:47:56Z</dc:date>
    </item>
    <item>
      <title>Re: Batch reading text files with special characters the variable names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Batch-reading-text-files-with-special-characters-the-variable/m-p/104825#M21855</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;One way is to just embed it inside of whatever logic you already have for looping over the input files.&lt;/P&gt;&lt;P&gt;Typically I would convert the above to a macro that accepts the input filename and target SAS dataset name as parameters.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-style: inherit; font-family: 'courier new', courier;"&gt;%macro onefile(infile=,ds=);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-style: inherit; font-family: 'courier new', courier;"&gt;filename datafile "&lt;STRONG&gt;&amp;amp;infile&lt;/STRONG&gt;"&lt;/SPAN&gt;&lt;SPAN style="font-family: 'courier new', courier; font-style: inherit; font-size: 10pt; line-height: 1.5em;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;...&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier; font-style: inherit; font-size: 10pt; line-height: 1.5em;"&gt;proc transpose data=tall out=&lt;STRONG&gt;&amp;amp;ds&lt;/STRONG&gt; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;...&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%mend onefile;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Then I would create a program to calls it once for each file.&lt;/P&gt;&lt;P&gt;For example it could be as simple as a data step that reads the output of a dir or ls command and writes the macro calls to a new file that can be %INCLUDED.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;filename code temp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;data files ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; infile 'ls *.txt' pipe truncover ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; input filename $200.;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; dsname=scan(filename,-2,'/.\');&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; file code;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; put '%onefile(infile=' filename ',ds=' dsname ')' ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%inc code / source2 ;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Jun 2013 18:03:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Batch-reading-text-files-with-special-characters-the-variable/m-p/104825#M21855</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-06-13T18:03:58Z</dc:date>
    </item>
    <item>
      <title>Re: Batch reading text files with special characters the variable names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Batch-reading-text-files-with-special-characters-the-variable/m-p/104826#M21856</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I finally got it to work, but another way which I think is simpler (it only required the addition of 2 lines of code, provided by tech support): input@; and translate and compress functions to get rid of/replace special characters. Here is the part of the code that changed (in the first section of the macro fileread)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;data var_names;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;length x1-x145 $30;&lt;/P&gt;&lt;P&gt;infile "C:\Users\pignon2\Dropbox\2013_chamber_experiment\05.29.13\&amp;amp;filein" dsd dlm='09'X firstobs=17 obs=17 missover lrecl=32767;&lt;/P&gt;&lt;P&gt;input @;&lt;/P&gt;&lt;P&gt;_infile_=translate(_infile_,'_','''');&lt;/P&gt;&lt;P&gt;_infile_=compress(_infile_," @%/.'?""");&lt;/P&gt;&lt;P&gt;input (x1-x145) ($) ;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Jun 2013 19:31:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Batch-reading-text-files-with-special-characters-the-variable/m-p/104826#M21856</guid>
      <dc:creator>charles_pignon1</dc:creator>
      <dc:date>2013-06-25T19:31:24Z</dc:date>
    </item>
  </channel>
</rss>

