<?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: Is there a simpler way to preserve 0s in my variables when exporting to CSV? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-simpler-way-to-preserve-0s-in-my-variables-when/m-p/705028#M216187</link>
    <description>&lt;P&gt;As it stands now, are the variables character or numeric?&amp;nbsp; If they are numeric, they don't contain leading zeros.&amp;nbsp; In fact, they don't contain any digits at all.&amp;nbsp; SAS stores the value (not a set of characters) for numeric variables.&amp;nbsp; If the variables are character but happen to contain only digits, you should be able to use a somewhat less cumbersome process.&amp;nbsp; At least I think this should work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Add an observation at the top of the data set.&amp;nbsp; Assign any variable that requires leading zeros a value of 'ABC' in that extra observation.&amp;nbsp; Then when you export, SAS should figure out that these are character variables and preserve leading zeros.&amp;nbsp; After the export, remove the extra row.&lt;/P&gt;</description>
    <pubDate>Thu, 10 Dec 2020 12:52:07 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2020-12-10T12:52:07Z</dc:date>
    <item>
      <title>Is there a simpler way to preserve 0s in my variables when exporting to CSV?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-simpler-way-to-preserve-0s-in-my-variables-when/m-p/704984#M216161</link>
      <description>I am currently working with a dataset that looks somewhat like this, albeit with around 210 variables and 25031 rows in total.&lt;BR /&gt;DATA PUBLIC.BCUSTOMERS;&lt;BR /&gt;INPUT CUSTNO $ B1STAT JOB_ID;&lt;BR /&gt;CARDS;&lt;BR /&gt;C19291203 002103 0010&lt;BR /&gt;C19291204 000091 0001&lt;BR /&gt;C19291205 000000 0101&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;BR /&gt;As I have lost the original CSV file for this table I decided to export this dataset as a CSV file for backup purposes, but whenever I do this, columns such as "B1STAT" and "JOB_ID" that have 0s in their first digits tend to be exported with a few digits missing (e.g.B1STAT and JOB_ID for CUSTNO C19291204 is exported as 91 and 1).&amp;amp;nbsp;My original idea was to first convert such variables to character variables and add a random letter to the front of the row using CATX() (e.g.B1STAT and JOB_ID for CUSTNO C19291204 would become A000091 and B0001) and export the data like that, after which I would use SUBSTR() to delete the letter from the column. Problem is, there's at least 60 + variables like this and repeating the process for all such variables manually seems rather cumbersome, and I am still unfamiliar with macros at the moment.&lt;BR /&gt;&amp;amp;nbsp;&lt;BR /&gt;Is there a way to ensure that the table is exported correctly in a simpler manner instead of doing what I described above?</description>
      <pubDate>Fri, 11 Dec 2020 00:20:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-simpler-way-to-preserve-0s-in-my-variables-when/m-p/704984#M216161</guid>
      <dc:creator>DanielCoben93</dc:creator>
      <dc:date>2020-12-11T00:20:53Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a simpler way to preserve 0s in my variables when exporting to CSV?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-simpler-way-to-preserve-0s-in-my-variables-when/m-p/705001#M216170</link>
      <description>&lt;P&gt;Variables&amp;nbsp;B1STAT JOB_ID are numbers in your example.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So they don't have meaningful leading numbers. So exporting them as 91 and 1 is sensible.&lt;/P&gt;
&lt;P&gt;You need to either create a character variable using the Z., or write out the numeric value&amp;nbsp;using the Z. format.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Dec 2020 09:28:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-simpler-way-to-preserve-0s-in-my-variables-when/m-p/705001#M216170</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-12-10T09:28:08Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a simpler way to preserve 0s in my variables when exporting to CSV?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-simpler-way-to-preserve-0s-in-my-variables-when/m-p/705016#M216178</link>
      <description>&lt;P&gt;Bad example: the variable b1stat and job_id don't have leading zeros in the dataset. If you want leading zeros you have to attach the appropriate z-format or change the variable to be alphanumeric. Also note that csv-files must not be opened with Excel, as that &lt;EM&gt;tool&lt;/EM&gt; "optimises" the data it reads without further noticing what was changed.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Dec 2020 10:43:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-simpler-way-to-preserve-0s-in-my-variables-when/m-p/705016#M216178</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-12-10T10:43:53Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a simpler way to preserve 0s in my variables when exporting to CSV?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-simpler-way-to-preserve-0s-in-my-variables-when/m-p/705027#M216186</link>
      <description>&lt;P&gt;See this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA BCUSTOMERS;
INPUT CUSTNO $ B1STAT JOB_ID;
CARDS;
C19291203 002103 0010
C19291204 000091 0001
C19291205 000000 0101
;

proc print noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;    CUSTNO     B1STAT    JOB_ID

   C1929120     2103        10 
   C1929120       91         1 
   C1929120        0       101 
&lt;/PRE&gt;
&lt;P&gt;no leading zeroes there.&lt;/P&gt;
&lt;P&gt;Now see this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA BCUSTOMERS;
INPUT CUSTNO $ B1STAT :$6. JOB_ID :$4.;
CARDS;
C19291203 002103 0010
C19291204 000091 0001
C19291205 000000 0101
;

proc print noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;  CUSTNO     B1STAT    JOB_ID

 C1929120    002103     0010 
 C1929120    000091     0001 
 C1929120    000000     0101 
&lt;/PRE&gt;
&lt;P&gt;Codes should always be stored as character.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And yes, &lt;STRONG&gt;never&lt;/STRONG&gt; &lt;EM&gt;inspect&lt;/EM&gt; CSV files with Excel. Use a text editor (e.g. Notepad++) for this.&lt;/P&gt;
&lt;P&gt;And be very careful with importing strings consisting of numbers solely into Excel.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Dec 2020 12:51:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-simpler-way-to-preserve-0s-in-my-variables-when/m-p/705027#M216186</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-12-10T12:51:17Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a simpler way to preserve 0s in my variables when exporting to CSV?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-simpler-way-to-preserve-0s-in-my-variables-when/m-p/705028#M216187</link>
      <description>&lt;P&gt;As it stands now, are the variables character or numeric?&amp;nbsp; If they are numeric, they don't contain leading zeros.&amp;nbsp; In fact, they don't contain any digits at all.&amp;nbsp; SAS stores the value (not a set of characters) for numeric variables.&amp;nbsp; If the variables are character but happen to contain only digits, you should be able to use a somewhat less cumbersome process.&amp;nbsp; At least I think this should work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Add an observation at the top of the data set.&amp;nbsp; Assign any variable that requires leading zeros a value of 'ABC' in that extra observation.&amp;nbsp; Then when you export, SAS should figure out that these are character variables and preserve leading zeros.&amp;nbsp; After the export, remove the extra row.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Dec 2020 12:52:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-simpler-way-to-preserve-0s-in-my-variables-when/m-p/705028#M216187</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2020-12-10T12:52:07Z</dc:date>
    </item>
  </channel>
</rss>

