<?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: Forcing character length to be equal for characters, numbers, spaces and dots in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Forcing-character-length-to-be-equal-for-characters-numbers/m-p/229863#M54431</link>
    <description>&lt;P&gt;Thank you for the suggestion!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to deliver the file in .csv format however.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, there cannot be spaces between the variables which the solution you suggested includes (this is why I change spaces into &amp;amp; characters before concating, then use the cat function for concating the variables, and then change the &amp;amp; characters back into spaces - this only leaves spaces where there are blank/missing characters from the values) - I can manage this by changing the starting position of the variables however so this is not a problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="line-height: 20px;"&gt;Can I use a combination of&amp;nbsp;the put sentence you suggested with an export to csv?&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 14 Oct 2015 10:39:14 GMT</pubDate>
    <dc:creator>MichaelJustesen</dc:creator>
    <dc:date>2015-10-14T10:39:14Z</dc:date>
    <item>
      <title>Forcing character length to be equal for characters, numbers, spaces and dots</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Forcing-character-length-to-be-equal-for-characters-numbers/m-p/229861#M54429</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a table with multiple data rows for multiple variables. My issue is that some of the variables in some of the data rows are missing, and when I concate all the variables to one field, SAS assigns a different length to the missing values than to other values.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need my export to have the same exact placement of each variable (whether or not it is blank or not) but I cannot achieve this as the data rows with missing values take up less space than the other data rows.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have attached 2 pictures of what my output looks like, and what it should look like.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My code is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*LENGTH FORMATTING*/&lt;/P&gt;&lt;P&gt;DATA total_formated;&lt;/P&gt;&lt;P&gt;set CVR_no_incl;&lt;/P&gt;&lt;P&gt;Country1 = put(country,2.);&lt;BR /&gt;Rcd_type1 = put(Rcd_type, 1.);&lt;BR /&gt;char_dealer1 = put(left(char_dealer), 10.);&lt;BR /&gt;char_Inv_nbr1 = put(left(char_Inv_nbr), 7.);&lt;BR /&gt;char_Doc_type1 = put(right(char_Doc_type), 3.);&lt;BR /&gt;char_Doc_date1 = put(right(char_Doc_date), 8.);&lt;BR /&gt;char_Outstanding_amount1 = put(right(char_Outstanding_amount), 13.);&lt;BR /&gt;char_Credit_limit1 = put(right(char_Credit_limit), 13.);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*REPLACES BLANKS WITHIN VARIABLES WITH &amp;amp; FOR CONCATE WITHOUT SPACES*/&lt;/P&gt;&lt;P&gt;Data And_instead_of_blank;&lt;/P&gt;&lt;P&gt;set total_formated;&lt;/P&gt;&lt;P&gt;Country1 = tranwrd(Country1, ' ', '&amp;amp;');&lt;BR /&gt;Rcd_type1 = tranwrd(Rcd_type1, ' ', '&amp;amp;');&lt;BR /&gt;char_dealer1 = tranwrd(char_dealer1, ' ', '&amp;amp;');&lt;BR /&gt;char_Inv_nbr1 = tranwrd(char_Inv_nbr1, ' ', '&amp;amp;');&lt;BR /&gt;char_Doc_type1 = tranwrd(char_Doc_type1, ' ', '&amp;amp;');&lt;BR /&gt;char_Doc_date1 = tranwrd(char_Doc_date1, ' ', '&amp;amp;');&lt;BR /&gt;char_Outstanding_amount1 = tranwrd(char_Outstanding_amount1, ' ', '&amp;amp;');&lt;BR /&gt;char_Credit_limit1 = tranwrd(char_Credit_limit1, ' ', '&amp;amp;');&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data Ready_for_concate;&lt;/P&gt;&lt;P&gt;set And_instead_of_blank;&lt;/P&gt;&lt;P&gt;length&lt;BR /&gt;Country1 $2&lt;BR /&gt;Rcd_type1 $1&lt;BR /&gt;char_dealer1 $10&lt;BR /&gt;char_Inv_nbr1 $7&lt;BR /&gt;char_Doc_type1 $3&lt;BR /&gt;char_Doc_date1 $8&lt;BR /&gt;char_Outstanding_amount1 $13&lt;BR /&gt;char_Credit_limit1 $13;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*CONCATENATES TO A SINGLE STRING*/&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;/P&gt;&lt;P&gt;create table Concatenated as&lt;/P&gt;&lt;P&gt;select cat(Country1, Rcd_type1, char_dealer1, char_Inv_nbr1, char_Doc_type1, char_Doc_date1, char_Outstanding_amount1, char_Credit_limit1) as Concatenated&lt;/P&gt;&lt;P&gt;from Ready_for_concate;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*REPLACES &amp;amp; WITH BLANKS IN CONCATENATED STRING WITHOUT SPACES/DELIMITERS*/&lt;/P&gt;&lt;P&gt;Data Ready_for_export;&lt;/P&gt;&lt;P&gt;set Concatenated;&lt;/P&gt;&lt;P&gt;Concatenated = tranwrd(Concatenated, '&amp;amp;', ' ');&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone help me?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BR /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/12009iD9B849AD14503E52/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="My output.png" title="My output.png" /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/12010i1AD36C220B94B8E6/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="Output should look like.png" title="Output should look like.png" /&gt;</description>
      <pubDate>Wed, 14 Oct 2015 10:00:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Forcing-character-length-to-be-equal-for-characters-numbers/m-p/229861#M54429</guid>
      <dc:creator>MichaelJustesen</dc:creator>
      <dc:date>2015-10-14T10:00:37Z</dc:date>
    </item>
    <item>
      <title>Re: Forcing character length to be equal for characters, numbers, spaces and dots</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Forcing-character-length-to-be-equal-for-characters-numbers/m-p/229862#M54430</link>
      <description>&lt;P&gt;Why you are not writing directly to ascii file with defined columns:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;filename out 'C:\test.txt';&lt;BR /&gt;data have;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; set have;&lt;BR /&gt;file out ;&lt;BR /&gt;put @1 Country @3 Rcd_type @4 char_dealer @14 char_Inv_nbr @21 char_Doc_type @24 char_Doc_date @31 char_Outstanding_amount @44 char_Credit_limit;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Oct 2015 10:19:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Forcing-character-length-to-be-equal-for-characters-numbers/m-p/229862#M54430</guid>
      <dc:creator>AskoLötjönen</dc:creator>
      <dc:date>2015-10-14T10:19:10Z</dc:date>
    </item>
    <item>
      <title>Re: Forcing character length to be equal for characters, numbers, spaces and dots</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Forcing-character-length-to-be-equal-for-characters-numbers/m-p/229863#M54431</link>
      <description>&lt;P&gt;Thank you for the suggestion!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to deliver the file in .csv format however.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, there cannot be spaces between the variables which the solution you suggested includes (this is why I change spaces into &amp;amp; characters before concating, then use the cat function for concating the variables, and then change the &amp;amp; characters back into spaces - this only leaves spaces where there are blank/missing characters from the values) - I can manage this by changing the starting position of the variables however so this is not a problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="line-height: 20px;"&gt;Can I use a combination of&amp;nbsp;the put sentence you suggested with an export to csv?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Oct 2015 10:39:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Forcing-character-length-to-be-equal-for-characters-numbers/m-p/229863#M54431</guid>
      <dc:creator>MichaelJustesen</dc:creator>
      <dc:date>2015-10-14T10:39:14Z</dc:date>
    </item>
    <item>
      <title>Re: Forcing character length to be equal for characters, numbers, spaces and dots</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Forcing-character-length-to-be-equal-for-characters-numbers/m-p/229864#M54432</link>
      <description>&lt;P&gt;If it's a .csv then there is no reason to use a fixed width output format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just use Proc Export&lt;/P&gt;
&lt;P&gt;&lt;A href="https://support.sas.com/documentation/cdl/en/proc/67916/HTML/default/viewer.htm#n0ku4pxzx3d2len10ozjgyjbrpl9.htm" target="_blank"&gt;https://support.sas.com/documentation/cdl/en/proc/67916/HTML/default/viewer.htm#n0ku4pxzx3d2len10ozjgyjbrpl9.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Oct 2015 11:03:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Forcing-character-length-to-be-equal-for-characters-numbers/m-p/229864#M54432</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2015-10-14T11:03:05Z</dc:date>
    </item>
    <item>
      <title>Re: Forcing character length to be equal for characters, numbers, spaces and dots</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Forcing-character-length-to-be-equal-for-characters-numbers/m-p/230070#M54449</link>
      <description>&lt;P&gt;Hi.&amp;nbsp; If you want a CSV file, you&amp;nbsp;can just use PROC PRINT, for example ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;ods listing close;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;ods results off;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;ods csv file='z:\class.csv';&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;proc print data=sashelp.class noobs;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;ods csv close;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;ods listing;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;ods results;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;partial view of CLASS.CSV ...&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;"Name","Sex","Age","Height","Weight"&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;"Alfred","M",14,69.0,112.5&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;"Alice","F",13,56.5,84.0&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;"Barbara","F",13,65.3,98.0&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;"Carol","F",14,62.8,102.5&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;"Henry","M",14,63.5,102.5&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you just want a file with fixed with output for all variables with the numbers right justified ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;* Z format adds leading zeroes;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;data _null_;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;file 'z:\fixed.txt';&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;set CVR_no_incl;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;put&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;country&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;z2.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;Rcd_type&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;z1.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;char_dealer&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; z10.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;char_Inv_nbr&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;z7.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;char_Doc_type&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;z3.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;char_Doc_date&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;z8.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;char_Outstanding_amount&amp;nbsp; z13.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;char_Credit_limit&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; z13.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;* rounds height and weight, adds leading zeroes;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;data _null_;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;file 'z:\class.txt';&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;set sashelp.class;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;put&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;age&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;z5.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;height&amp;nbsp;&amp;nbsp; z5.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;weight&amp;nbsp;&amp;nbsp; z5.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;partial view of CLASS.TXT ...&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;000140006900113&lt;BR /&gt;000130005700084&lt;BR /&gt;000130006500098&lt;BR /&gt;000140006300103&lt;BR /&gt;000140006400103&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Oct 2015 12:47:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Forcing-character-length-to-be-equal-for-characters-numbers/m-p/230070#M54449</guid>
      <dc:creator>MikeZdeb</dc:creator>
      <dc:date>2015-10-15T12:47:55Z</dc:date>
    </item>
  </channel>
</rss>

