<?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: Macro in Data infile statement csv file in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-in-Data-infile-statement-csv-file/m-p/464962#M30074</link>
    <description>&lt;P&gt;Thanks you very much! It's work, this is what i needed!&lt;/P&gt;</description>
    <pubDate>Fri, 25 May 2018 07:14:06 GMT</pubDate>
    <dc:creator>luciacossaro</dc:creator>
    <dc:date>2018-05-25T07:14:06Z</dc:date>
    <item>
      <title>Macro in Data infile statement csv file</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-in-Data-infile-statement-csv-file/m-p/464547#M30017</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Is my first time with SAS's macro and i want to import several csv file with a data step using INFILE (to can change the formats and informats).&lt;BR /&gt;I tried this code but i don't know how to define a macro's variable to make variate the data set's name for each file imported.&lt;/P&gt;&lt;P&gt;I think that the statement "(table_name=)" is wrong but i don't know how to specify this.&lt;/P&gt;&lt;P&gt;I need your help, thank you very much!&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;%MACRO import (fichier=) (table_name=);
DATA WORK.&amp;amp;table_name;
INFILE "/data/XXX/Lignes/&amp;amp;fichier"
LRECL=603
ENCODING="LATIN9"
TERMSTR=CRLF
DLM=';' FIRSTOBS=2
MISSOVER
DSD ;
INPUT
'VARIABLE A'n : $27.
vARIABLE B: $34.

FORMAT
'VARIABLE A'n $27.
vARIABLE B $34.

INFORMAT
'VARIABLE A'n $27.
vARIABLE B $34.

RUN;

%MEND;

%import (fichier=file_AB.csv);
%import (table_name=table_sas_AB);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 May 2018 19:44:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-in-Data-infile-statement-csv-file/m-p/464547#M30017</guid>
      <dc:creator>luciacossaro</dc:creator>
      <dc:date>2018-05-23T19:44:01Z</dc:date>
    </item>
    <item>
      <title>Re: Macro in Data infile statement csv file</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-in-Data-infile-statement-csv-file/m-p/464563#M30022</link>
      <description>&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token macrobound"&gt;%MACRO&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;import&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;fichier&lt;SPAN class="token operator"&gt;=,&lt;/SPAN&gt;table_name&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;DATA&lt;/SPAN&gt; WORK&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;table_name&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token statement"&gt;INFILE&lt;/SPAN&gt; &lt;SPAN class="token string"&gt;"/data/XXX/Lignes/&amp;amp;fichier"&lt;/SPAN&gt;
LRECL&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;603&lt;/SPAN&gt;
ENCODING&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;"LATIN9"&lt;/SPAN&gt;
TERMSTR&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;CRLF
DLM&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;';'&lt;/SPAN&gt; FIRSTOBS&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;2&lt;/SPAN&gt;
MISSOVER
DSD &lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;INPUT&lt;/SPAN&gt;
&lt;SPAN class="token string"&gt;'VARIABLE A'&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;n&lt;/SPAN&gt; : &lt;SPAN class="token punctuation"&gt;$&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;27&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;
vARIABLE B: &lt;SPAN class="token punctuation"&gt;$&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;34&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;

&lt;SPAN class="token procnames"&gt;FORMAT&lt;/SPAN&gt;
&lt;SPAN class="token string"&gt;'VARIABLE A'&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;n&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;$&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;27&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;
vARIABLE B &lt;SPAN class="token punctuation"&gt;$&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;34&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;

&lt;SPAN class="token statement"&gt;INFORMAT&lt;/SPAN&gt;
&lt;SPAN class="token string"&gt;'VARIABLE A'&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;n&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;$&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;27&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;
vARIABLE B &lt;SPAN class="token punctuation"&gt;$&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;34&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;

&lt;SPAN class="token procnames"&gt;RUN&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;

&lt;SPAN class="token macrobound"&gt;%MEND&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;

&lt;SPAN class="token macroname"&gt;%import&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;fichier&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;file_AB&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;csv, table_name&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;table_sas_AB&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For this code to work all the files your trying to import must have same data pattern as you mentioned in INPUT statement.&lt;/P&gt;</description>
      <pubDate>Wed, 23 May 2018 20:10:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-in-Data-infile-statement-csv-file/m-p/464563#M30022</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-05-23T20:10:57Z</dc:date>
    </item>
    <item>
      <title>Re: Macro in Data infile statement csv file</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-in-Data-infile-statement-csv-file/m-p/464564#M30023</link>
      <description>&lt;P&gt;That's reasonably close.&amp;nbsp; You need to combine the macro calls into one.&amp;nbsp; First, when defining the macro:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro import (fichier=, table_name=);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then when calling the macro:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%import (fichier=file_AB.csv, table_name=table_sas_AB)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also note, it looks like&amp;nbsp; you are missing a few semicolons.&amp;nbsp; The INPUT, FORMAT, and INFORMAT statements all should end with a semicolon.&amp;nbsp; In this particular program, however, it wouldn't hurt anything to just get rid of the FORMAT and INFORMAT statements.&lt;/P&gt;</description>
      <pubDate>Wed, 23 May 2018 20:11:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-in-Data-infile-statement-csv-file/m-p/464564#M30023</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-05-23T20:11:32Z</dc:date>
    </item>
    <item>
      <title>Re: Macro in Data infile statement csv file</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-in-Data-infile-statement-csv-file/m-p/464572#M30025</link>
      <description>&lt;P&gt;If all of these "files" have the same layout and you expect to combine the data together (a &lt;STRONG&gt;very common&lt;/STRONG&gt; activity with similar datasets) you would be much better off assigning a single informat, possibly a little longer than the longest expected value and then use the same program to import all of them with the same characteristics.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Otherwise when you go to combine the data you will get messages about variables with different lengths in different data sets possibly resulting in truncated data. A likely actually truncated data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And unless there is supervisor standing over me with a whip I would never use a name literal variable name like 'Variable A'n as that just adds to lots of headaches keeping that spelled correctly in code.&lt;/P&gt;</description>
      <pubDate>Wed, 23 May 2018 20:37:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-in-Data-infile-statement-csv-file/m-p/464572#M30025</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-05-23T20:37:15Z</dc:date>
    </item>
    <item>
      <title>Re: Macro in Data infile statement csv file</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-in-Data-infile-statement-csv-file/m-p/464962#M30074</link>
      <description>&lt;P&gt;Thanks you very much! It's work, this is what i needed!&lt;/P&gt;</description>
      <pubDate>Fri, 25 May 2018 07:14:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-in-Data-infile-statement-csv-file/m-p/464962#M30074</guid>
      <dc:creator>luciacossaro</dc:creator>
      <dc:date>2018-05-25T07:14:06Z</dc:date>
    </item>
    <item>
      <title>Re: Macro in Data infile statement csv file</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-in-Data-infile-statement-csv-file/m-p/464963#M30075</link>
      <description>&lt;P&gt;Thank you very much for your reponse. Yes, the code paste here was a little part from the original code, i forgotten a &lt;SPAN&gt;semicolons&amp;nbsp;&lt;/SPAN&gt;when i do copy-paste but in the original there are all&amp;nbsp;&lt;SPAN&gt;semicolons.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 25 May 2018 07:17:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-in-Data-infile-statement-csv-file/m-p/464963#M30075</guid>
      <dc:creator>luciacossaro</dc:creator>
      <dc:date>2018-05-25T07:17:05Z</dc:date>
    </item>
    <item>
      <title>Re: Macro in Data infile statement csv file</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-in-Data-infile-statement-csv-file/m-p/464965#M30076</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Thank you very much for your reponse. Yes, in the original code i chosse the maximal value for every variable for all files and the names variable A was only to describe the structure of code; but is not the name of the variables which i use.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Now i hqave another problem.&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV&gt;To know which informat choose in every variable, I did before an import with the sas's assistant for one file and I copied the program from the log and I modified thant a little.&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;The problem is: in this code there is a parameter 'LRECL' with a determinate value choosed by Sas but if I set the same value (or the default value) for all files the informat and format choosed do not work in the others files, and is very difficult to know which value set for every file because I have a lot of files.&lt;/DIV&gt;&lt;DIV&gt;Do you know another way to make that?&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I don't understand why the format and informat works in this situation and do not work in another.&lt;/DIV&gt;</description>
      <pubDate>Fri, 25 May 2018 07:24:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-in-Data-infile-statement-csv-file/m-p/464965#M30076</guid>
      <dc:creator>luciacossaro</dc:creator>
      <dc:date>2018-05-25T07:24:38Z</dc:date>
    </item>
  </channel>
</rss>

