<?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: Changing variable Format with proc import in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Changing-variable-Format-with-proc-import/m-p/487542#M127067</link>
    <description>Can you please show a sample code of datastep to change variable format, informat, length, type&lt;BR /&gt;</description>
    <pubDate>Thu, 16 Aug 2018 18:06:54 GMT</pubDate>
    <dc:creator>Rookie_123</dc:creator>
    <dc:date>2018-08-16T18:06:54Z</dc:date>
    <item>
      <title>Changing variable Format with proc import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-variable-Format-with-proc-import/m-p/487509#M127049</link>
      <description>&lt;P&gt;TLDR:&lt;/P&gt;&lt;P&gt;How to specify column format, informat, lenght, type in&amp;nbsp;&lt;STRONG&gt;PROC IMPORT.&lt;/STRONG&gt;My database is in xlsx format&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Longer Version&lt;/P&gt;&lt;P&gt;I am importing my 3 excel databases A, B, C&amp;nbsp;&lt;STRONG&gt;PROC IMPORT.&amp;nbsp;&lt;/STRONG&gt;I want to append this datasets after importing.&lt;/P&gt;&lt;P&gt;These databases consists of date variables in different columns&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Database A will have values in &amp;nbsp;column DateA&lt;/P&gt;&lt;P&gt;Database B will have values in &amp;nbsp;column DateB&lt;/P&gt;&lt;P&gt;Database C will have values in column DateC&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All the three database will have columns DateA, DateB, DateC.But values in those columns will depend on what database it is.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So when I import Database A the column type of DateB and DateC is set to character since they dont have values in them.How can I specify at the import itself that DateB and DateC should be considered as Date type.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Another problem is the lenghts, format, informat of columns is set as it is in Database A.Due to which when I try to append B with A it gives me a truncation warning.I dont want my data to be truncated.&lt;/P&gt;&lt;P&gt;I have in all 50 columns so manually specifying each columns lenght, format, informat etc. wont be a feasible thing.Is there any better alternative&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Aug 2018 16:54:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-variable-Format-with-proc-import/m-p/487509#M127049</guid>
      <dc:creator>Rookie_123</dc:creator>
      <dc:date>2018-08-16T16:54:59Z</dc:date>
    </item>
    <item>
      <title>Re: Changing variable Format with proc import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-variable-Format-with-proc-import/m-p/487537#M127066</link>
      <description>&lt;P&gt;If you want to have control over variable attributes, forget the Excel file format. Importing it always involves guessing on the part of SAS.&lt;/P&gt;
&lt;P&gt;If you want to have control, save your data to csv files and read those with a data step.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Aug 2018 18:03:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-variable-Format-with-proc-import/m-p/487537#M127066</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-08-16T18:03:52Z</dc:date>
    </item>
    <item>
      <title>Re: Changing variable Format with proc import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-variable-Format-with-proc-import/m-p/487542#M127067</link>
      <description>Can you please show a sample code of datastep to change variable format, informat, length, type&lt;BR /&gt;</description>
      <pubDate>Thu, 16 Aug 2018 18:06:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-variable-Format-with-proc-import/m-p/487542#M127067</guid>
      <dc:creator>Rookie_123</dc:creator>
      <dc:date>2018-08-16T18:06:54Z</dc:date>
    </item>
    <item>
      <title>Re: Changing variable Format with proc import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-variable-Format-with-proc-import/m-p/487547#M127068</link>
      <description>&lt;P&gt;You do not run a data step to&amp;nbsp;&lt;EM&gt;change&lt;/EM&gt; anything, you&amp;nbsp;&lt;EM&gt;read&lt;/EM&gt; data from a file format that can be reliably used.&lt;/P&gt;
&lt;P&gt;You can use proc import&amp;nbsp;&lt;EM&gt;once&lt;/EM&gt; for the csv file, then copy the data step from the log, and adapt it to your needs.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Aug 2018 18:25:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-variable-Format-with-proc-import/m-p/487547#M127068</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-08-16T18:25:11Z</dc:date>
    </item>
    <item>
      <title>Re: Changing variable Format with proc import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-variable-Format-with-proc-import/m-p/487566#M127070</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/225671"&gt;@Rookie_123&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Can you please show a sample code of datastep to change variable format, informat, length, type&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you run Proc Import on a CSV file the log will contain an example. That was how I generated the skeleton for this code which I modified slightly by changing the lengths of some variables to match the length of counterparts in another data set.&lt;/P&gt;
&lt;P&gt;Not changing anything, reading as needed:&lt;/P&gt;
&lt;PRE&gt;data lib.AddressRaw    ;
   infile Siradd delimiter = ',' MISSOVER DSD lrecl=32767 firstobs=2 ;
   informat School_Name $80. ;
   informat Type $8. ;
   informat Title $16. ;
   informat First_Name $17. ;
   informat Last_Name $15. ;
   informat Phone $12. ;
   informat Fax $12. ;
   informat Email $44. ;
   informat District_Code $15. ;
   informat District $26. ;
   informat Address $32. ;
   informat City $17. ;
   informat County $10. ;
   informat State $2. ;
   informat Zip $5. ;
   informat Principal_Title $35. ;
   informat Principal_First_Name $14. ;
   informat Principal_Last_Name $14. ;
   input
      School_Name $
      Type $
      Title $
      First_Name $
      Last_Name $
      Phone $
      Fax $
      Email $
      District_Code $
      District $
      Address $
      City $
      County $
      State $
      Zip $
      Principal_Title $
      Principal_First_Name $
      Principal_Last_Name $
   ;
run;&lt;/PRE&gt;
&lt;P&gt;The SIRADD is a file reference pointing to a CSV file. In this case I wanted everything to be character so things like district_code or ZIP that have only digits involved are read as character since I don't do any calculations on those.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;An informat used in this manner will set the variable type and length. I had no need to assign any specific format to these values but could add a FORMAT statement if that were needed.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Aug 2018 19:39:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-variable-Format-with-proc-import/m-p/487566#M127070</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-08-16T19:39:16Z</dc:date>
    </item>
  </channel>
</rss>

