<?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: Importing and labeling multiple CSV files without coding variables by hand in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Importing-and-labeling-multiple-CSV-files-without-coding/m-p/483226#M125299</link>
    <description>&lt;P&gt;See my example code in my updated original reply.&lt;/P&gt;
&lt;P&gt;If you want to have the variable order in the dataset match the CSV file's order then add a RETAIN &amp;amp;VARLIST statement before the IF THEN statement. Otherwise the order will match the order in the TEMPLATE dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the metadata sheet is also variable then post an example of the metadata sheet to see how to automate the process of generating the TEMPLATE dataset from metadata.&amp;nbsp; Or&amp;nbsp;instead of&amp;nbsp;the IF 0 THEN SET statement you could generate a series of ATTRIB statements derived from the metadata and eliminate the need for the TEMPLATE dataset.&lt;/P&gt;</description>
    <pubDate>Wed, 01 Aug 2018 22:37:43 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2018-08-01T22:37:43Z</dc:date>
    <item>
      <title>Importing and labeling multiple CSV files without coding variables by hand</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-and-labeling-multiple-CSV-files-without-coding/m-p/483172#M125274</link>
      <description>&lt;P class="p1"&gt;I'm looking for help with general strategy and not necessarily each step of my code, which is why I'm not including any specific code here. If anyone is able to talk me through how they might accomplish the following, I'd be so appreciative. Using Base SAS 9.4.&amp;nbsp;&lt;/P&gt;&lt;P class="p2"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p1"&gt;&lt;STRONG&gt;Data description:&lt;/STRONG&gt;&lt;/P&gt;&lt;P class="p1"&gt;~60 CSV files that each contain a unique set of data&lt;/P&gt;&lt;P class="p1"&gt;-Each file is a part of the whole. All of the variables, labels and formats are contained in one sheet, in columns, listed according to their dataset grouping. However, the order that the variables are listed in the master sheet are not the same order that the variables appear in the datasets.&amp;nbsp;&lt;/P&gt;&lt;P class="p2"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p1"&gt;&lt;STRONG&gt;I need to:&lt;/STRONG&gt;&lt;/P&gt;&lt;P class="p1"&gt;-Import each CSV file, retaining the original file name for the SAS datasets&lt;/P&gt;&lt;P class="p1"&gt;-Save each as a separate SAS dataset (they are not being combined)&lt;/P&gt;&lt;P class="p1"&gt;-Label the variables&lt;/P&gt;&lt;P class="p2"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p1"&gt;I've been wrestling with various strategies to accomplish this task, but can't figure out which one makes the most sense. At the end of the day, I need a solution that is dynamic and doesn't require me to read in each dataset individually and hard code the variables (I have to do this so much at my job that I don't have time for a manual process).&lt;/P&gt;&lt;P class="p2"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p1"&gt;The piece that I'm struggling with the most is whether or not I need to chop up the master sheet in order to apply the labels. I can't figure out a solution to refer to the master sheet that only pulls out the labels that I need for any particular dataset.&lt;/P&gt;&lt;P class="p2"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p1"&gt;&lt;STRONG&gt;Should I:&lt;/STRONG&gt;&lt;/P&gt;&lt;P class="p1"&gt;1. Use proc import to create temp datasets, then apply the labels in another step&lt;/P&gt;&lt;P class="p1"&gt;2. Use a data step to read in the data and apply the labels in one step...guessing this would require variable sorting first&lt;/P&gt;&lt;P class="p1"&gt;3. Something else?&lt;/P&gt;</description>
      <pubDate>Wed, 01 Aug 2018 19:27:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-and-labeling-multiple-CSV-files-without-coding/m-p/483172#M125274</guid>
      <dc:creator>viola</dc:creator>
      <dc:date>2018-08-01T19:27:41Z</dc:date>
    </item>
    <item>
      <title>Re: Importing and labeling multiple CSV files without coding variables by hand</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-and-labeling-multiple-CSV-files-without-coding/m-p/483191#M125283</link>
      <description>&lt;P&gt;Personnaly, I would go for option #1. Before applying the label and formatting, I'd probably include a step to validate that all expected columns are present and have the right type. This would allow you to discard the file right away&amp;nbsp;and send a notification. Saving you the trouble of regularly scrubbing the logs in search of "ERROR:".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I try as much as possible to assume that the data I receive could be wrong and put in place the right validations.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Aug 2018 20:08:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-and-labeling-multiple-CSV-files-without-coding/m-p/483191#M125283</guid>
      <dc:creator>ybolduc</dc:creator>
      <dc:date>2018-08-01T20:08:41Z</dc:date>
    </item>
    <item>
      <title>Re: Importing and labeling multiple CSV files without coding variables by hand</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-and-labeling-multiple-CSV-files-without-coding/m-p/483216#M125295</link>
      <description>&lt;P&gt;Use the sheet with the metadata to build a dataset with information about the variables.&lt;/P&gt;
&lt;P&gt;Then for each of your 60 files follow this process.&lt;/P&gt;
&lt;P&gt;1) Read the header row to see what variables are included and what order they appear.&lt;/P&gt;
&lt;P&gt;2) Combine with the metadata to get the information on the variable definitions.&lt;/P&gt;
&lt;P&gt;3) Use that to write a data step that can read the file.&lt;/P&gt;
&lt;P&gt;4) Run the generated data step&amp;nbsp;to convert the CSV file into a dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A couple of questions about how complex your setup is.&lt;/P&gt;
&lt;P&gt;1) Do the names used in the header rows of the CSV files always match the names in the metadata sheet?&amp;nbsp; or are these CSV files created adhoc with typos in the header rows?&lt;/P&gt;
&lt;P&gt;2) Does the same variable name always mean the exact same variable definition (same type/length/format/label) even when it appears in different CSV files?&amp;nbsp; For example is the variable AGE always a number? Or is AGE used in some sheets for a character age category variable?&lt;/P&gt;
&lt;P&gt;3) Can you tell from the name of the CSV file what variables should be in it, even if you don't the order they will appear?&amp;nbsp; Or do the 60 CSV files have adhoc or random sets of variables?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming that the variables are defined consistently across all of the files you could just create a single template dataset that have all of the possible variables.&amp;nbsp; Make sure to attach informats to the variables (like DATE, TIME and DATETIME fields) that will need them. There is no need to attach informats to most character and numeric variables since SAS already knows how to read numbers and strings from a CSV file without you needing to instruct it to use a specific informat.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So assuming this template dataset is named TEMPLATE, then your program for processing one file is as simple as:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let filename=physical csv filename;
%let dsname=want;

data _null_;
  infile "&amp;amp;filename" obs=1;
  input;
  call symputx('varlist',tranwrd(_infile_,',',' '));
run;

data &amp;amp;dsname ;
  if 0 then set template (keep=&amp;amp;varlist);
  infile "&amp;amp;filename" dsd firstobs=2 truncover ;
  input (&amp;amp;varlist) (+0);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 01 Aug 2018 22:27:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-and-labeling-multiple-CSV-files-without-coding/m-p/483216#M125295</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-08-01T22:27:28Z</dc:date>
    </item>
    <item>
      <title>Re: Importing and labeling multiple CSV files without coding variables by hand</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-and-labeling-multiple-CSV-files-without-coding/m-p/483224#M125297</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;, thank you. To answer your questions:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1) The names in the header rows will always match the names in the metadata sheet. The CSV files are generated by a standard export procedure that will always produce the&amp;nbsp;same set of headers.&amp;nbsp;&lt;/P&gt;&lt;P&gt;2) The variable names will always meet the definitions set by the metadata sheet - if one variable appears in more than one of the datasets it will always be defined in the same way.&amp;nbsp;&lt;/P&gt;&lt;P&gt;3) The CSV files always have the same sets of variables. They are exports of data collection forms, where the variables are in the order that they appear on the form. However, in the metadata sheet, they are not listed in the order they appear on the collection form.&amp;nbsp;No adhoc or random variables.&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;Use the sheet with the metadata to build a dataset with information about the variables.&lt;/P&gt;&lt;P&gt;Then for each of your 60 files follow this process.&lt;/P&gt;&lt;P&gt;1) Read the header row to see what variables are included and what order they appear.&lt;/P&gt;&lt;P&gt;2) Combine with the metadata to get the information on the variable definitions.&lt;/P&gt;&lt;P&gt;3) Use that to write a data step that can read the file.&lt;/P&gt;&lt;P&gt;4) Run the generated data step&amp;nbsp;to convert the CSV file into a dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A couple of questions about how complex your setup is.&lt;/P&gt;&lt;P&gt;1) Do the names used in the header rows of the CSV files always match the names in the metadata sheet?&amp;nbsp; or are these CSV files created adhoc with typos in the header rows?&lt;/P&gt;&lt;P&gt;2) Does the same variable name always mean the exact same variable definition (same type/length/format/label) even when it appears in different CSV files?&amp;nbsp; For example is the variable AGE always a number? Or is AGE used in some sheets for a character age category variable?&lt;/P&gt;&lt;P&gt;3) Can you tell from the name of the CSV file what variables should be in it, even if you don't the order they will appear?&amp;nbsp; Or do the 60 CSV files have adhoc or random sets of variables?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Aug 2018 22:31:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-and-labeling-multiple-CSV-files-without-coding/m-p/483224#M125297</guid>
      <dc:creator>viola</dc:creator>
      <dc:date>2018-08-01T22:31:23Z</dc:date>
    </item>
    <item>
      <title>Re: Importing and labeling multiple CSV files without coding variables by hand</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-and-labeling-multiple-CSV-files-without-coding/m-p/483226#M125299</link>
      <description>&lt;P&gt;See my example code in my updated original reply.&lt;/P&gt;
&lt;P&gt;If you want to have the variable order in the dataset match the CSV file's order then add a RETAIN &amp;amp;VARLIST statement before the IF THEN statement. Otherwise the order will match the order in the TEMPLATE dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the metadata sheet is also variable then post an example of the metadata sheet to see how to automate the process of generating the TEMPLATE dataset from metadata.&amp;nbsp; Or&amp;nbsp;instead of&amp;nbsp;the IF 0 THEN SET statement you could generate a series of ATTRIB statements derived from the metadata and eliminate the need for the TEMPLATE dataset.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Aug 2018 22:37:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-and-labeling-multiple-CSV-files-without-coding/m-p/483226#M125299</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-08-01T22:37:43Z</dc:date>
    </item>
    <item>
      <title>Re: Importing and labeling multiple CSV files without coding variables by hand</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-and-labeling-multiple-CSV-files-without-coding/m-p/483228#M125300</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/80715"&gt;@viola&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;, thank you. To answer your questions:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) The names in the header rows will always match the names in the metadata sheet. The CSV files are generated by a standard export procedure that will always produce the&amp;nbsp;same set of headers.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) The variable names will always meet the definitions set by the metadata sheet - if one variable appears in more than one of the datasets it will always be defined in the same way.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3) The CSV files always have the same sets of variables. They are exports of data collection forms, where the variables are in the order that they appear on the form. However, in the metadata sheet, they are not listed in the order they appear on the collection form.&amp;nbsp;No adhoc or random variables.&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Use the sheet with the metadata to build a dataset with information about the variables.&lt;/P&gt;
&lt;P&gt;Then for each of your 60 files follow this process.&lt;/P&gt;
&lt;P&gt;1) Read the header row to see what variables are included and what order they appear.&lt;/P&gt;
&lt;P&gt;2) Combine with the metadata to get the information on the variable definitions.&lt;/P&gt;
&lt;P&gt;3) Use that to write a data step that can read the file.&lt;/P&gt;
&lt;P&gt;4) Run the generated data step&amp;nbsp;to convert the CSV file into a dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A couple of questions about how complex your setup is.&lt;/P&gt;
&lt;P&gt;1) Do the names used in the header rows of the CSV files always match the names in the metadata sheet?&amp;nbsp; or are these CSV files created adhoc with typos in the header rows?&lt;/P&gt;
&lt;P&gt;2) Does the same variable name always mean the exact same variable definition (same type/length/format/label) even when it appears in different CSV files?&amp;nbsp; For example is the variable AGE always a number? Or is AGE used in some sheets for a character age category variable?&lt;/P&gt;
&lt;P&gt;3) Can you tell from the name of the CSV file what variables should be in it, even if you don't the order they will appear?&amp;nbsp; Or do the 60 CSV files have adhoc or random sets of variables?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Your responses sound as if the CSV files all have the same layout. It should be practical to create a basic data step that will read the data in the same format by changing the 1) the input file name and 2) the name of the output file name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would start with something like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc import datafile="c:\path\inputfilename.csv"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; out= mylib.mydatasetname&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dbms=CSV&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; replace&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; guessingrows=max;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; getnames=yes;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The log will contain a data step program created to read that file.&lt;/P&gt;
&lt;P&gt;Copy the data step to the editor.&lt;/P&gt;
&lt;P&gt;Remove line numbers if they appeared in the log.&lt;/P&gt;
&lt;P&gt;Check with your metadata sheet to see if the variables have the appropriate length. Example: Metatdata says that variable Sitename should be 15 characters but the program shows an informat (which would set the length) of $12. because of the actual data read. Change the informat from $12. to $15. (If paranoid make it longer in case they sneak a data change in on your).&lt;/P&gt;
&lt;P&gt;Verify that character type variables have a $ type informat. Values like identification numbers might be guessed to be numeric by import procedure so instead of "003456" you get a number value of 3456. Most likely that involves changing a BEST12. or BEST32. to $10. or similar.&lt;/P&gt;
&lt;P&gt;Check that values that should be numeric are not read with a $ format. This may happen if an infrequently used column is missing for all of the records in your data. If that happens often the informat will be $1.&lt;/P&gt;
&lt;P&gt;If a value represents a date, time or datetime it may help to check on the informat and format assigned to make sure they are read as such. If your data looks like an obvious date such as 12/24/2016 or 10JAN2017 then SAS will likely guess correctly. But if you have a value like 121288 (12 Dec 1988) that may not be guessed correctly. There are a largish number of possible date, time and datetime informats.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the variable names you get don't quite match what you expected you can do text search and replaces to likely get them "right". At this point I also usually add LABEL statements so I have in the data a better description than "Val1". Labels let you have up to 256 characters to describe a variable such as :&lt;/P&gt;
&lt;P&gt;Label val1="Measured groundwater temperature (C)";&lt;/P&gt;
&lt;P&gt;Test you modified program to reread the data and see if it looks good.&lt;/P&gt;
&lt;P&gt;Fix things if not.&lt;/P&gt;
&lt;P&gt;When you are done you can read other files by replacing the infile name and the output data set.&lt;/P&gt;
&lt;P&gt;There are even code steps that will let read a whole bunch of CSV files at one time.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Aug 2018 22:56:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-and-labeling-multiple-CSV-files-without-coding/m-p/483228#M125300</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-08-01T22:56:17Z</dc:date>
    </item>
    <item>
      <title>Re: Importing and labeling multiple CSV files without coding variables by hand</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-and-labeling-multiple-CSV-files-without-coding/m-p/483510#M125375</link>
      <description>&lt;P&gt;Thanks for the code example&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;. I think this could work. The metadata sheet will look something like this:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Variable&amp;nbsp; &amp;nbsp; Group&amp;nbsp; &amp;nbsp; Label&amp;nbsp; &amp;nbsp; &amp;nbsp;Format&amp;nbsp;&lt;/P&gt;&lt;P&gt;var1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;label1&amp;nbsp; &amp;nbsp; &amp;nbsp;format1&lt;/P&gt;&lt;P&gt;var2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;label 2&amp;nbsp; &amp;nbsp; format2&lt;/P&gt;&lt;P&gt;var3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;label 3&amp;nbsp; &amp;nbsp; format3&lt;/P&gt;&lt;P&gt;var4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;label 4&amp;nbsp; &amp;nbsp; format 4&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Each of the 60 datasets will only need the variables in its respective group, if that makes sense. So somehow I need to subset the metadata sheet with the relevant variables for each dataset.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;, I would be more willing to copy and paste the proc import code if I didn't have to do that 60 times over. Each of the CSV files has a different variable list.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Aug 2018 18:10:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-and-labeling-multiple-CSV-files-without-coding/m-p/483510#M125375</guid>
      <dc:creator>viola</dc:creator>
      <dc:date>2018-08-02T18:10:27Z</dc:date>
    </item>
    <item>
      <title>Re: Importing and labeling multiple CSV files without coding variables by hand</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-and-labeling-multiple-CSV-files-without-coding/m-p/484946#M125930</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;- I attempted to use your code below but am running into errors with the _infile_ piece. I'm getting a varlist that spits out as "VAR1" "VAR2" - why am I seeing quotes around the variables, and how can I get rid of them?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p2"&gt;147&lt;/P&gt;&lt;P class="p2"&gt;148&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;data &amp;amp;dsname ;&lt;/P&gt;&lt;P class="p2"&gt;149&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;retain &amp;amp;varlist;&lt;/P&gt;&lt;P class="p2"&gt;NOTE: Line generated by the macro variable "VARLIST".&lt;/P&gt;&lt;P class="p2"&gt;1 &lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;"STUDYID" "SITEID" "SITENAME" "SUBJID" "EPOCH" "VISITID" "VISIT" "VISITNUM"&lt;/P&gt;&lt;P class="p2"&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;---------&lt;/P&gt;&lt;P class="p2"&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;22&lt;/P&gt;&lt;P class="p2"&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;76&lt;/P&gt;&lt;P class="p2"&gt;1&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;! "VISITDY" "Visit Repeat Key" "DOMAIN" "Form Repeat Key" "Item Group Repeat Key" "Scheduled&lt;/P&gt;&lt;P class="p2"&gt;1&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;! Date" "Completed Date" "DMDAT" "BRTHDAT" "SEX" "CHILDBR" "RACE" "RACEOTH"&lt;/P&gt;&lt;P class="p2"&gt;ERROR 22-322: Syntax error, expecting one of the following: a name, ;, _ALL_, _CHARACTER_,&lt;/P&gt;&lt;P class="p2"&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;_CHAR_, _NUMERIC_.&lt;/P&gt;&lt;P class="p1"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p2"&gt;ERROR 76-322: Syntax error, statement will be ignored.&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;PRE&gt;&lt;CODE class=" language-sas"&gt;%let filename=physical csv filename;
%let dsname=want;

data _null_;
  infile "&amp;amp;filename" obs=1;
  input;
  call symputx('varlist',tranwrd(_infile_,',',' '));
run;

data &amp;amp;dsname ;
  if 0 then set template (keep=&amp;amp;varlist);
  infile "&amp;amp;filename" dsd firstobs=2 truncover ;
  input (&amp;amp;varlist) (+0);
run&lt;/CODE&gt;&lt;/PRE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Aug 2018 23:40:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-and-labeling-multiple-CSV-files-without-coding/m-p/484946#M125930</guid>
      <dc:creator>viola</dc:creator>
      <dc:date>2018-08-07T23:40:28Z</dc:date>
    </item>
    <item>
      <title>Re: Importing and labeling multiple CSV files without coding variables by hand</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-and-labeling-multiple-CSV-files-without-coding/m-p/484951#M125931</link>
      <description>&lt;P&gt;In a CSV file quotes are only required around values that include the delimiter or quotes.&amp;nbsp; But extra quotes are allowed and will be stripped.&amp;nbsp; Looks like your source file had a header line like&lt;/P&gt;
&lt;PRE&gt;"STUDYID","SITEID","SITENAME",...&lt;/PRE&gt;
&lt;P&gt;Instead of what a normal CSV file would have of:&lt;/P&gt;
&lt;PRE&gt;STUDYID,SITEID,SITENAME,...&lt;/PRE&gt;
&lt;P&gt;You could try just removing them.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;call symputx('varlist',tranwrd(compress(_infile_,'"'),',',' '));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or make that step more complicated.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Aug 2018 23:48:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-and-labeling-multiple-CSV-files-without-coding/m-p/484951#M125931</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-08-07T23:48:56Z</dc:date>
    </item>
    <item>
      <title>Re: Importing and labeling multiple CSV files without coding variables by hand</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-and-labeling-multiple-CSV-files-without-coding/m-p/484972#M125934</link>
      <description>&lt;P&gt;The error is due to the retain statement not expecting quotes.&lt;/P&gt;
&lt;P&gt;You&amp;nbsp;can remove them on the fly when unneeded like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data &amp;amp;dsname. ;
  retain %sysfunc(compress(&amp;amp;varlist.,%str(%")));

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Aug 2018 02:45:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-and-labeling-multiple-CSV-files-without-coding/m-p/484972#M125934</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-08-08T02:45:45Z</dc:date>
    </item>
  </channel>
</rss>

