<?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 CSV to SAS conversion issue, the variable format was keep changing in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/CSV-to-SAS-conversion-issue-the-variable-format-was-keep/m-p/640276#M190665</link>
    <description>&lt;P&gt;I am facing issue while importing CSV files to SAS.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I had tried to import csv files to SAS few days ago using proc import and the expected format of the variables in the output was character and we have seen them correctly, but yesterday when I had used the same production data few data sets were having numeric and other were having character variables in the output which is not obvious. We were not sure why this is happening.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would be thankful if you can please help us with a solution&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If possible can someone please suggest a macro that will automatically read the csv files from folder in one go and convert them to SAS. I have got this csv files from Trifacta where this issue is happening. Not sure if i am doing something wring or any issue with the data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
    <pubDate>Thu, 16 Apr 2020 06:09:21 GMT</pubDate>
    <dc:creator>Ravindra_</dc:creator>
    <dc:date>2020-04-16T06:09:21Z</dc:date>
    <item>
      <title>CSV to SAS conversion issue, the variable format was keep changing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CSV-to-SAS-conversion-issue-the-variable-format-was-keep/m-p/640276#M190665</link>
      <description>&lt;P&gt;I am facing issue while importing CSV files to SAS.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I had tried to import csv files to SAS few days ago using proc import and the expected format of the variables in the output was character and we have seen them correctly, but yesterday when I had used the same production data few data sets were having numeric and other were having character variables in the output which is not obvious. We were not sure why this is happening.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would be thankful if you can please help us with a solution&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If possible can someone please suggest a macro that will automatically read the csv files from folder in one go and convert them to SAS. I have got this csv files from Trifacta where this issue is happening. Not sure if i am doing something wring or any issue with the data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Apr 2020 06:09:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CSV-to-SAS-conversion-issue-the-variable-format-was-keep/m-p/640276#M190665</guid>
      <dc:creator>Ravindra_</dc:creator>
      <dc:date>2020-04-16T06:09:21Z</dc:date>
    </item>
    <item>
      <title>Re: CSV to SAS conversion issue, the variable format was keep changing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CSV-to-SAS-conversion-issue-the-variable-format-was-keep/m-p/640279#M190667</link>
      <description>&lt;P&gt;If you want consistent results from a data import from text files, DO NOT (I repeat:&amp;nbsp;&lt;STRONG&gt;NOT&lt;/STRONG&gt;) use proc import more than once (at maximum once to get a blueprint of the needed data step code).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ideally, you do not use proc import at all, but write the data step yourself, following the documentation you got for your source file(s).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But if you're not yet firm with data step coding (something you need to rectify ASAP), you can use proc import once, copy the code that it created from the log, and adapt that code to your needs (as said above, use the documentation you got with the file).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Apr 2020 06:21:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CSV-to-SAS-conversion-issue-the-variable-format-was-keep/m-p/640279#M190667</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-16T06:21:48Z</dc:date>
    </item>
    <item>
      <title>Re: CSV to SAS conversion issue, the variable format was keep changing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CSV-to-SAS-conversion-issue-the-variable-format-was-keep/m-p/640389#M190739</link>
      <description>Hi Kurt,&lt;BR /&gt;&lt;BR /&gt;Thank you for your reply, i have got almost 28 files to import and i had used proc import in a macro and i am facing this issue.&lt;BR /&gt;&lt;BR /&gt;Can you please let me know if you have any macro that can read multiple csv files to SAS without any issue.&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Ravindra.</description>
      <pubDate>Thu, 16 Apr 2020 11:24:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CSV-to-SAS-conversion-issue-the-variable-format-was-keep/m-p/640389#M190739</guid>
      <dc:creator>Ravindra_</dc:creator>
      <dc:date>2020-04-16T11:24:34Z</dc:date>
    </item>
    <item>
      <title>Re: CSV to SAS conversion issue, the variable format was keep changing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CSV-to-SAS-conversion-issue-the-variable-format-was-keep/m-p/640391#M190741</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Hi Kurt, Thank you for your reply, i have got almost 28 files to import and i had used proc import in a macro and i am facing this issue. Can you please let me know if you have any macro that can read multiple csv files to SAS without any issue. Thanks, Ravindra.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Apr 2020 11:27:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CSV-to-SAS-conversion-issue-the-variable-format-was-keep/m-p/640391#M190741</guid>
      <dc:creator>Ravindra_</dc:creator>
      <dc:date>2020-04-16T11:27:23Z</dc:date>
    </item>
    <item>
      <title>Re: CSV to SAS conversion issue, the variable format was keep changing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CSV-to-SAS-conversion-issue-the-variable-format-was-keep/m-p/640394#M190743</link>
      <description>&lt;P&gt;If you have a number of files with identical structure to import, and the contents of all these files should end up in one SAS dataset, you do not need a macro; you can read all these files in one data step, either by using wildcards in the INFILE statement, or using a dynamic infile name.&lt;/P&gt;
&lt;P&gt;So we need to know:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;do these files have identical structure?&lt;/LI&gt;
&lt;LI&gt;do you want the data in separate datasets, or in one dataset?&lt;/LI&gt;
&lt;LI&gt;how are the filenames structured?&lt;/LI&gt;
&lt;LI&gt;are these files the only files in the source directory, or do we need to exclude other files?&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Supplying some example lines to illustrate the structure would be great, along with information taken from the file documentation.&lt;/P&gt;
&lt;P&gt;To post textual data, use the &amp;lt;/&amp;gt; button:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Bildschirmfoto 2020-04-07 um 08.32.59.png"&gt;&lt;img src="https://communities.sas.com/skins/images/70F8802BAA6255D55FBEC62A8226FB10/responsive_peak/images/image_not_found.png" alt="Bildschirmfoto 2020-04-07 um 08.32.59.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Apr 2020 11:33:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CSV-to-SAS-conversion-issue-the-variable-format-was-keep/m-p/640394#M190743</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-16T11:33:10Z</dc:date>
    </item>
    <item>
      <title>Re: CSV to SAS conversion issue, the variable format was keep changing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CSV-to-SAS-conversion-issue-the-variable-format-was-keep/m-p/640395#M190744</link>
      <description>&lt;P&gt;1. &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;'s advice is to be followed: proc import does not guarantee that the files will be imported the way you want.&lt;/P&gt;
&lt;P&gt;Only a data step allows you full control.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. Are you using option guessingrows ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3. Do all the files have the same structure?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;4. This forum has many examples of answers to the issue of reading files from a folder; have you looked at them?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Apr 2020 11:33:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CSV-to-SAS-conversion-issue-the-variable-format-was-keep/m-p/640395#M190744</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-04-16T11:33:56Z</dc:date>
    </item>
    <item>
      <title>Re: CSV to SAS conversion issue, the variable format was keep changing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CSV-to-SAS-conversion-issue-the-variable-format-was-keep/m-p/640400#M190748</link>
      <description>&lt;P&gt;Thank you for reply&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1) Can you please help me do that using data step as a macro, as we are not allowed to write attributes within data step and there are 28 different files not sure how to handle this. So i have created macrio using proc import and did that.&lt;/P&gt;&lt;P&gt;2) Yes i am using guessingrows option without which there a variable which i was unable to read the whole text in a value, so i am forced to use that.&lt;/P&gt;&lt;P&gt;3)Every file is different having different variable length and formats&lt;/P&gt;&lt;P&gt;4) I have seen the post from past but didn't find that useful to me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please suggest a solution for this. Thanks for your time.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Apr 2020 11:43:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CSV-to-SAS-conversion-issue-the-variable-format-was-keep/m-p/640400#M190748</guid>
      <dc:creator>Ravindra_</dc:creator>
      <dc:date>2020-04-16T11:43:34Z</dc:date>
    </item>
    <item>
      <title>Re: CSV to SAS conversion issue, the variable format was keep changing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CSV-to-SAS-conversion-issue-the-variable-format-was-keep/m-p/640409#M190751</link>
      <description>&lt;P&gt;&lt;EM&gt;&amp;gt; but yesterday when I had used the same production data few data sets were having numeric and other&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;proc import may not allow much flexibility in terms of output, but it will give you the same result for the same file.&lt;/P&gt;
&lt;P&gt;Your files changed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2 questions:&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&amp;gt; please help me do that using data step .. we are not allowed to write attributes within data step&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;How does this reconcile?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You must choose one: output data sets have a known layout OR use proc import.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Which one?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the 28 files are different, you need 28 different data steps.&lt;/P&gt;
&lt;P&gt;You can use proc import 28 times, which requires less coding, but then the data set might end up being different from what you want or expect.&lt;/P&gt;
&lt;P&gt;If you have 28 data steps, a macro is hardly useful.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the data is very similar, one data step might be usable, and you'll have to split the input statements to use depending on the file you read.&lt;/P&gt;
&lt;P&gt;Like &lt;A href="https://communities.sas.com/t5/SAS-Programming/Reading-a-text-file/m-p/630347#M186602" target="_self"&gt;this&lt;/A&gt; person does in their question (don't look at the answers, they are irrelevant to your post).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Apr 2020 12:00:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CSV-to-SAS-conversion-issue-the-variable-format-was-keep/m-p/640409#M190751</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-04-16T12:00:42Z</dc:date>
    </item>
    <item>
      <title>Re: CSV to SAS conversion issue, the variable format was keep changing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CSV-to-SAS-conversion-issue-the-variable-format-was-keep/m-p/640411#M190752</link>
      <description>&lt;P&gt;If, for a given file, you need consistent structure because datasets need to be combined later, then you &lt;STRONG&gt;MUST NOT(!)&lt;/STRONG&gt; use proc import. &lt;STRONG&gt;PERIOD.&lt;/STRONG&gt; It is &lt;STRONG&gt;IMPOSSIBLE&lt;/STRONG&gt; to get consistent results with proc import, as each separate run makes guesses about structure from the data it sees, and different data (lengths of strings, for example) WILL result in different variable lengths. This is what you have experienced, and to remedy this, you &lt;STRONG&gt;HAVE TO&lt;/STRONG&gt; use a consistent data step for each file layout. &lt;STRONG&gt;There is no way around this.&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Apr 2020 12:06:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CSV-to-SAS-conversion-issue-the-variable-format-was-keep/m-p/640411#M190752</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-16T12:06:26Z</dc:date>
    </item>
    <item>
      <title>Re: CSV to SAS conversion issue, the variable format was keep changing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CSV-to-SAS-conversion-issue-the-variable-format-was-keep/m-p/640421#M190754</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp; and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp; thanks a lot for taking time in replying on this issue&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;please find the code i had used and do you mind providing a possible solution for this issue. Thank you&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%MACRO CSV_to_SAS(InData = , OutData =);&lt;/P&gt;&lt;P&gt;libname out "&amp;amp;outdata";&lt;/P&gt;&lt;P&gt;/*proc datasets library=out kill; Quit;*/&lt;/P&gt;&lt;P&gt;/*Find out the files present in the Input directory*/&lt;BR /&gt;data yfiles;&lt;BR /&gt;length fref $8 filenm $80;&lt;BR /&gt;rc = filename(fref, "&amp;amp;indata.");&lt;BR /&gt;if rc = 0 then&lt;BR /&gt;do;&lt;BR /&gt;did = dopen(fref);&lt;BR /&gt;rc = filename(fref);&lt;BR /&gt;end;&lt;BR /&gt;else&lt;BR /&gt;do;&lt;BR /&gt;length msg $200.;&lt;BR /&gt;msg = sysmsg();&lt;BR /&gt;put msg=;&lt;BR /&gt;did = .;&lt;BR /&gt;end;&lt;BR /&gt;if did &amp;lt;= 0&lt;BR /&gt;then&lt;BR /&gt;putlog 'ERR' 'OR: Unable to open directory.';&lt;BR /&gt;dnum = dnum(did);&lt;BR /&gt;do i = 1 to dnum;&lt;BR /&gt;filenm = dread(did, i);&lt;BR /&gt;/* If this entry is a file, then output. */&lt;BR /&gt;fid = mopen(did, filenm);&lt;BR /&gt;if fid &amp;gt; 0&lt;BR /&gt;then&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;rc = dclose(did);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;/*Keep only .CSV records from file names and dataset names assigned*/&lt;BR /&gt;data filenme(keep = filenm filenm_wosp1 filenm_wosp);&lt;BR /&gt;/* Dataset name can consists of maximum 32 characters*/&lt;BR /&gt;length filenm_wosp1 filenm_wosp $32.;&lt;BR /&gt;set yfiles;&lt;BR /&gt;/* Keeping only .CSV records*/&lt;BR /&gt;if SUBSTR(UPCASE(TRIM(filenm)),LENGTH(TRIM(filenm))-3) eq ".CSV";&lt;/P&gt;&lt;P&gt;/* Converting Symbols(!@#$%^&amp;amp;()-+=[{}];',.`~ ) from the file name into _(Under score) as Dataset name cannot consist of symbols*/&lt;BR /&gt;if indexc(TRIM(filenm),"!@#$%^&amp;amp;()-+=[{}];',.`~ ") &amp;gt; 0 then do;&lt;BR /&gt;filenm_wosp1 = translate(substr(filenm,1,length(trim(filenm))-4),"_______________________","!@#$%^&amp;amp;()-+=[{}];',.`~ ");&lt;BR /&gt;end;&lt;BR /&gt;else do;&lt;BR /&gt;filenm_wosp1 = substr(filenm,1,length(trim(filenm))-4);&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;/* Putting _(Under score) for the file names starting with numbers as Dataset name cannot start with numbers*/&lt;BR /&gt;if indexc(TRIM(filenm_wosp1),"1234567890") = 1 then&lt;BR /&gt;filenm_wosp = cat("_",substr(strip(filenm_wosp1),1,31));&lt;BR /&gt;else&lt;BR /&gt;filenm_wosp = filenm_wosp1;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;/* If file names are more than 32 charcters and program will convert it into 32 character */&lt;BR /&gt;/* dataset name then to avoid the overlapping of datasets due to same name _number(_1,_2..) */&lt;BR /&gt;/* would be added in the last to differentiate the name*/&lt;/P&gt;&lt;P&gt;Proc sort data=filenme; by filenm_wosp filenm; run;&lt;/P&gt;&lt;P&gt;data filenme1;&lt;BR /&gt;retain count;&lt;BR /&gt;set filenme;&lt;BR /&gt;by filenm_wosp filenm;&lt;BR /&gt;if first.filenm_wosp then count=0;&lt;BR /&gt;count+1;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table filenme2 as select *,count(*) as cnt&lt;BR /&gt;from filenme1 group by filenm_wosp having cnt &amp;gt; 0 order by filenm_wosp;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;data filenme3;&lt;BR /&gt;set filenme2;&lt;BR /&gt;if cnt &amp;gt; 1 then substr(filenm_wosp,(length(filenm_wosp)-length(strip(put(count,best.)))))="_"||strip(put(count,best.));&lt;BR /&gt;else filenm_wosp=filenm_wosp;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data _null_;&lt;BR /&gt;set filenme3;&lt;BR /&gt;/* Renaming file names similar to dataset names(filenm_wosp) as for some file names, it may contain &amp;amp; or %, which will be read as macro statement while importing data and throw an error*/&lt;BR /&gt;RC=rename("&amp;amp;indata.\"||strip(filenm), "&amp;amp;indata.\"||strip(filenm_wosp)||substr(strip(filenm),length(trim(filenm))-3), "file");&lt;BR /&gt;/* Importing files from the provided path*/&lt;BR /&gt;call execute ('PROC IMPORT OUT= Out.' ||strip(filenm_wosp)||&lt;BR /&gt;' DATAFILE= "&amp;amp;InData.\'||strip(filenm_wosp)||substr(strip(filenm),length(trim(filenm))-3)||'"&lt;BR /&gt;DBMS=CSV REPLACE; GETNAMES=YES; GUESSINGROWS =32767; DATAROW=2; run; ');&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;/*Renaming the files to original names*/&lt;BR /&gt;data _null_;&lt;BR /&gt;set filenme3;&lt;BR /&gt;RC1=rename("&amp;amp;indata.\"||strip(filenm_wosp)||substr(strip(filenm),length(trim(filenm))-3), "&amp;amp;indata.\"||strip(filenm), "file");&lt;BR /&gt;Run;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Apr 2020 12:24:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CSV-to-SAS-conversion-issue-the-variable-format-was-keep/m-p/640421#M190754</guid>
      <dc:creator>Ravindra_</dc:creator>
      <dc:date>2020-04-16T12:24:21Z</dc:date>
    </item>
    <item>
      <title>Re: CSV to SAS conversion issue, the variable format was keep changing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CSV-to-SAS-conversion-issue-the-variable-format-was-keep/m-p/640424#M190756</link>
      <description>&lt;P&gt;I suggest that you start with creating the necessary data steps for each separate file layout.&lt;/P&gt;
&lt;P&gt;You can wrap all these codes into one macro by using a parameter for this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro import(infile=,outds=,layout=);
%if &amp;amp;layout = 1 %then do;
/* code for first layout */
%end;
%else %if &amp;amp;layout = 2 %then %do;
......
%end;
%else %put Wrong layout code!;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In your code that reads the filenames and selects certain files, associate certain filenames with their layouts, and call the macro accordingly.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Apr 2020 12:32:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CSV-to-SAS-conversion-issue-the-variable-format-was-keep/m-p/640424#M190756</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-16T12:32:22Z</dc:date>
    </item>
    <item>
      <title>Re: CSV to SAS conversion issue, the variable format was keep changing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CSV-to-SAS-conversion-issue-the-variable-format-was-keep/m-p/640508#M190806</link>
      <description>&lt;P&gt;You still haven't explained what the actual problem is.&amp;nbsp; As others have said if you run PROC IMPORT twice on the EXACT SAME input file you will get the EXACT SAME output file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if you are seeing differences it is because of one of two issues.&lt;/P&gt;
&lt;P&gt;1) You are getting multiple copies of the same TYPE of file.&amp;nbsp; So you have one from today and one from yesterday. Or one from company A and one from company B.&amp;nbsp; Even if they have the same columns in the same order then because there is NO information in a CSV file about the data type or length of the variables PROC IMPORT must guess. So different data yields different guesses.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) You are getting multiple different data files and have one or more common variables and you would like the variables to have the same definition across all of the files.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So which describes your situation? (or do you have both things going on?)&lt;/P&gt;</description>
      <pubDate>Thu, 16 Apr 2020 18:25:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CSV-to-SAS-conversion-issue-the-variable-format-was-keep/m-p/640508#M190806</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-04-16T18:25:12Z</dc:date>
    </item>
    <item>
      <title>Re: CSV to SAS conversion issue, the variable format was keep changing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CSV-to-SAS-conversion-issue-the-variable-format-was-keep/m-p/640545#M190828</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/260204"&gt;@Ravindra_&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you for reply&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) Can you please help me do that using data step as a macro,&lt;STRONG&gt; as we are not allowed to write attributes within data step&lt;/STRONG&gt; and there are 28 different files not sure how to handle this. So i have created macrio using proc import and did that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Do you have some document that tells you what the content of each of these files is supposed to look like such as length of variable, date and expected appearance, column order? If you have such a document then using that to write the code should be acceptable.If not you may need to talk to who ever issued that policy about the manpower hours this is going to cost in "fixing" data that should have been read correctly one time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If no such document exists and you are going to guess every time you read files then you should bring that to the attention of management because you have no way to know what "correct" data actually would look like after it was read.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Apr 2020 20:26:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CSV-to-SAS-conversion-issue-the-variable-format-was-keep/m-p/640545#M190828</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-04-16T20:26:57Z</dc:date>
    </item>
    <item>
      <title>Re: CSV to SAS conversion issue, the variable format was keep changing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CSV-to-SAS-conversion-issue-the-variable-format-was-keep/m-p/640595#M190852</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;... we are not allowed to write attributes within data step ...&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;You should check on this. Either someone is setting rules that knows nothing about how to write SAS code. Or there is some nuance in this policy that did not get communicated properly.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Apr 2020 01:55:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CSV-to-SAS-conversion-issue-the-variable-format-was-keep/m-p/640595#M190852</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-04-17T01:55:21Z</dc:date>
    </item>
    <item>
      <title>Re: CSV to SAS conversion issue, the variable format was keep changing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CSV-to-SAS-conversion-issue-the-variable-format-was-keep/m-p/640603#M190858</link>
      <description>&lt;P&gt;thanks Kurt i will try this&lt;/P&gt;</description>
      <pubDate>Fri, 17 Apr 2020 03:45:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CSV-to-SAS-conversion-issue-the-variable-format-was-keep/m-p/640603#M190858</guid>
      <dc:creator>Ravindra_</dc:creator>
      <dc:date>2020-04-17T03:45:12Z</dc:date>
    </item>
    <item>
      <title>Re: CSV to SAS conversion issue, the variable format was keep changing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CSV-to-SAS-conversion-issue-the-variable-format-was-keep/m-p/640604#M190859</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp; thanks for your concern, i am having the same concern about our company having such policies and not sure how to handle this. I will suggest them to use a metadata having defined structure where we can look into and generate output accordingly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In this regard, i am having a small query, is it possible to automatically pick the metadata information having variable attribute information and map that with csv data and import that to SAS dataset. If it is possible how do we do that.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Apr 2020 03:52:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CSV-to-SAS-conversion-issue-the-variable-format-was-keep/m-p/640604#M190859</guid>
      <dc:creator>Ravindra_</dc:creator>
      <dc:date>2020-04-17T03:52:58Z</dc:date>
    </item>
    <item>
      <title>Re: CSV to SAS conversion issue, the variable format was keep changing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CSV-to-SAS-conversion-issue-the-variable-format-was-keep/m-p/640609#M190863</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/260204"&gt;@Ravindra_&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;&amp;nbsp;and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp; thanks for your concern, i am having the same concern about our company having such policies and not sure how to handle this. I will suggest them to use a metadata having defined structure where we can look into and generate output accordingly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;In this regard, i am having a small query, is it possible to automatically pick the metadata information having variable attribute information and map that with csv data and import that to SAS dataset. If it is possible how do we do that.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks again.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes, it is possible to use metadata to create data steps reading csv files. But compared to writing the data step directly, this is not trivial.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Apr 2020 05:27:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CSV-to-SAS-conversion-issue-the-variable-format-was-keep/m-p/640609#M190863</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-04-17T05:27:29Z</dc:date>
    </item>
    <item>
      <title>Re: CSV to SAS conversion issue, the variable format was keep changing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CSV-to-SAS-conversion-issue-the-variable-format-was-keep/m-p/640759#M190934</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/260204"&gt;@Ravindra_&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;&amp;nbsp;and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp; thanks for your concern, i am having the same concern about our company having such policies and not sure how to handle this. I will suggest them to use a metadata having defined structure where we can look into and generate output accordingly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this regard, i am having a small query, is it possible to automatically pick the metadata information having variable attribute information and map that with csv data and import that to SAS dataset. If it is possible how do we do that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks again.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Considering the number of different ways I have received "metadata" descriptions about source data files I would answer the "is it possible" with a "it probably depends".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am very leery of blind use of any such tool. If there is something that gets close and then you have a knowledgeable person review the generated data that might be the way to go.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One simple example of issues around automated generation could be variable names length and characters. SAS currently uses 32 characters and must letter, digit or underscore. I really don't like the options that allow use of the extended characters where you have to constantly refer to variables as "Some #garbage"n . And the heuristics for very long source variables that are identical for the first 32+ characters may result in some oddness indeed.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Apr 2020 15:00:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CSV-to-SAS-conversion-issue-the-variable-format-was-keep/m-p/640759#M190934</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-04-17T15:00:08Z</dc:date>
    </item>
    <item>
      <title>Re: CSV to SAS conversion issue, the variable format was keep changing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CSV-to-SAS-conversion-issue-the-variable-format-was-keep/m-p/640770#M190939</link>
      <description>&lt;P&gt;It can be done.&amp;nbsp; How depends on what your specific issues (risks) are with the data you are receiving.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the issue is that the column names are always valid, but the order and/or inclusion/exclusion of columns from a particular file can vary then you can read the header row only and use that to drive the creation of the program to read based on the expected format for that column.&amp;nbsp; It can even be as simple as something like: (1) Get variable names from header. (2) Generate a data step that defines the structure by reading in just those variables from a template dataset.&amp;nbsp; So something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  infile "myfile.txt" obs=1;
  input;
  call  symputx('varlist',translate(_infile_,' ',','));
run;
data want;
  if 0 then set mylib.template(keep=&amp;amp;varlist);
  infile "myfile.txt" dsd truncover firstobs=2;
  input &amp;amp;varlist;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could also read all of the files into a tall skinny file and then do your own logic to figure out what variable is what and what type of value it contains.&amp;nbsp; So something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data 
  files (keep=fileno filename)
  values(keep=fileno rowno colno value)
;
   length fileno rowno colno 8 value $200 fname filename $256;
   retain fileno 0 rowno 0;
   infile "c:\downloads\h*.csv" dsd truncover length=ll column=col filename=fname;
   input @;
   if fname ne lag(fname) then do;
       fileno+1; rowno=0; filename=fname; output files;
  end;
  rowno+1;
  do colno=1 by 1 until(col&amp;gt;ll);
      input value @;
      if value ne ' ' then output values;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;NOTE: The infile "c:\downloads\h*.csv" is:
      Filename=c:\downloads\Honda.csv,
      File List=c:\downloads\h*.csv,RECFM=V,
      LRECL=32767

NOTE: The infile "c:\downloads\h*.csv" is:
      Filename=c:\downloads\Hummer.csv,
      File List=c:\downloads\h*.csv,RECFM=V,
      LRECL=32767

NOTE: The infile "c:\downloads\h*.csv" is:
      Filename=c:\downloads\Hyundai.csv,
      File List=c:\downloads\h*.csv,RECFM=V,
      LRECL=32767

NOTE: 17 records were read from the infile "c:\downloads\h*.csv".
      The minimum record length was 75.
      The maximum record length was 110.
NOTE: 1 record was read from the infile "c:\downloads\h*.csv".
      The minimum record length was 68.
      The maximum record length was 68.
NOTE: 12 records were read from the infile "c:\downloads\h*.csv".
      The minimum record length was 83.
      The maximum record length was 92.
NOTE: The data set WORK.FILES has 3 observations and 2 variables.
NOTE: The data set WORK.VALUES has 450 observations and 4 variables.
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Apr 2020 15:47:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CSV-to-SAS-conversion-issue-the-variable-format-was-keep/m-p/640770#M190939</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-04-17T15:47:37Z</dc:date>
    </item>
  </channel>
</rss>

