<?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: Format Columns Character Length in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Format-Columns-Character-Length/m-p/786789#M32230</link>
    <description>&lt;P&gt;Show us the code you are using.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Show us a portion of your input data, as SAS data step code (&lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;instructions&lt;/A&gt;).&lt;/P&gt;</description>
    <pubDate>Mon, 20 Dec 2021 17:37:45 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2021-12-20T17:37:45Z</dc:date>
    <item>
      <title>Format Columns Character Length</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Format-Columns-Character-Length/m-p/786788#M32229</link>
      <description>&lt;P&gt;I've been working on the TSA Case Study, and when I imported the file, columns such as State, County, and City only have one character. So I thought the next step to fix this, would be to:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;format State $2.;&lt;/P&gt;&lt;P&gt;format County $20.;&lt;/P&gt;&lt;P&gt;format City $20.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The out put of this code did not produce an error, and the output table remained the same with each column on displaying one character. I also tried the length syntax and that also did not work.&amp;nbsp;&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;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Dec 2021 17:31:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Format-Columns-Character-Length/m-p/786788#M32229</guid>
      <dc:creator>ChadGotU</dc:creator>
      <dc:date>2021-12-20T17:31:42Z</dc:date>
    </item>
    <item>
      <title>Re: Format Columns Character Length</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Format-Columns-Character-Length/m-p/786789#M32230</link>
      <description>&lt;P&gt;Show us the code you are using.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Show us a portion of your input data, as SAS data step code (&lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;instructions&lt;/A&gt;).&lt;/P&gt;</description>
      <pubDate>Mon, 20 Dec 2021 17:37:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Format-Columns-Character-Length/m-p/786789#M32230</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-12-20T17:37:45Z</dc:date>
    </item>
    <item>
      <title>Re: Format Columns Character Length</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Format-Columns-Character-Length/m-p/786797#M32231</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/409540"&gt;@ChadGotU&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I've been working on the TSA Case Study, and when I imported the file, columns such as State, County, and City only have one character. So I thought the next step to fix this, would be to:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;format State $2.;&lt;/P&gt;
&lt;P&gt;format County $20.;&lt;/P&gt;
&lt;P&gt;format City $20.;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The out put of this code did not produce an error, and the output table remained the same with each column on displaying one character. I also tried the length syntax and that also did not work.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The FORMAT attached to a variable just impacts how the value is displayed when printed as TEXT, like in a report.&amp;nbsp; It does not change what is stored in any way.&amp;nbsp; So attaching the $20. to COUNTY will not change whether COUNTY contains 1 byte or 100 bytes, it just means that you only want it to print the first 20 bytes of the value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How did you "import" the data?&amp;nbsp; What type of file was it in before?&amp;nbsp; Or did you download it from some remote database system?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that if the source is a text file, like a CSV file, then don't bother to "import" it. Just write a data step to READ it and you will have complete control over how the variables are defined, including whether or not any display formats are permanently attached to the variables.&lt;/P&gt;</description>
      <pubDate>Mon, 20 Dec 2021 18:28:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Format-Columns-Character-Length/m-p/786797#M32231</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-12-20T18:28:39Z</dc:date>
    </item>
    <item>
      <title>Re: Format Columns Character Length</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Format-Columns-Character-Length/m-p/786804#M32232</link>
      <description>data work.tsa_claims_cleaned;&lt;BR /&gt;set tsa_claims_cleaned;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;if Claim_Type= "" then&lt;BR /&gt;Claim_Type="Unknown";&lt;BR /&gt;&lt;BR /&gt;if Claim_Site= "" then&lt;BR /&gt;Claim_Type="Unknown";&lt;BR /&gt;&lt;BR /&gt;if Disposition="" then&lt;BR /&gt;Disposition="Unknown";&lt;BR /&gt;&lt;BR /&gt;StateName=propcase(StateName);&lt;BR /&gt;State=upcase(State);&lt;BR /&gt;&lt;BR /&gt;format Date_Received mmddyy.;&lt;BR /&gt;format Incident_Date mmddyy.;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;format Date_Issues $12.;&lt;BR /&gt;Date_Issues="";&lt;BR /&gt;if Incident_Date= "." then&lt;BR /&gt;Date_Issues="Needs Review";&lt;BR /&gt;if Date_received= "." then&lt;BR /&gt;Date_Issues="Needs Review";&lt;BR /&gt;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;proc print data=work.tsa_claims_cleaned (obs=100);&lt;BR /&gt;run;&lt;BR /&gt;</description>
      <pubDate>Mon, 20 Dec 2021 18:40:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Format-Columns-Character-Length/m-p/786804#M32232</guid>
      <dc:creator>ChadGotU</dc:creator>
      <dc:date>2021-12-20T18:40:40Z</dc:date>
    </item>
    <item>
      <title>Re: Format Columns Character Length</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Format-Columns-Character-Length/m-p/786809#M32236</link>
      <description>&lt;P&gt;SAS will define a variable (set the type and the storage length) based on when it in the code the variable first appears (with some exceptions, like RETAIN statement).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So in your code if those variables are in the input dataset their type and length is defined when the SET statement is seen.&amp;nbsp; Otherwise the length is set by the comparison in the IF statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to modify the length of a character variable being read from an existing dataset then set the length before the SET statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So perhaps something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data tsa_claims_cleaned_2;
  set tsa_claims_cleaned;
  length Claim_Type Claim_Site Disposition $6  Date_Issues $12 ;

  if Claim_Type=" " then Claim_Type="Unknown";
  if Claim_Site=" " then Claim_Type="Unknown";
  if Disposition=" " then Disposition="Unknown";
  StateName=propcase(StateName);
  State=upcase(State);


  if Incident_Date=. then Date_Issues="Needs Review";
  else if Date_received=. then Date_Issues="Needs Review";
  else Date_Issues="";

  format Date_Received Incident_Date mmddyy10.;
  format _character_ ;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But if&amp;nbsp;Claim_Type, Claim_Site and Disposition already exist in&amp;nbsp;tsa_claims_cleaned and they are shorter than 6 bytes then you need to move the LENGTH statement for them to before the SET statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also:&lt;/P&gt;
&lt;P&gt;1)&amp;nbsp; Try not to overwrite your source dataset by using the same dataset name in the DATA and SET statement.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) If you change the length of character variable be careful that it does not already have a format attached to it that will only print some of the characters stored in the variable. You can use a FORMAT statement that just lists variables without any format specification after them to clear the formats attached.&lt;/P&gt;</description>
      <pubDate>Mon, 20 Dec 2021 19:04:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Format-Columns-Character-Length/m-p/786809#M32236</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-12-20T19:04:02Z</dc:date>
    </item>
  </channel>
</rss>

