<?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: Converting a char variable &amp;quot; 00x&amp;quot; to a numeric variable that looks the same: [blank sp in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Converting-a-char-variable-quot-00x-quot-to-a-numeric-variable/m-p/422832#M27261</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/183345"&gt;@Rhein&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Thanks, but how do I export it so that it keeps the blanks?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;How are you currently exporting the data? Provide code examples.&lt;/P&gt;
&lt;P&gt;There are multiple ways to send data elsewhere and each has advantages and disadvantages. Your specific method may be part of the issue, or the destination file, or how you examine the destination file (note Excel reformats lots of stuff without telling you).&lt;/P&gt;</description>
    <pubDate>Wed, 20 Dec 2017 18:52:46 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2017-12-20T18:52:46Z</dc:date>
    <item>
      <title>Converting a char variable " 00x" to a numeric variable that looks the same: [blank space]00x</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Converting-a-char-variable-quot-00x-quot-to-a-numeric-variable/m-p/422536#M27207</link>
      <description>&lt;P&gt;If x is any number from 1 to 9, how to convert a char variable that cointains the following: " 00x" to a numeric variable that keeps the same structure [blank space]00x (in proc sql)?&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2017 23:45:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Converting-a-char-variable-quot-00x-quot-to-a-numeric-variable/m-p/422536#M27207</guid>
      <dc:creator>Rhein</dc:creator>
      <dc:date>2017-12-19T23:45:49Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a char variable " 00x" to a numeric variable that looks the same: [blank sp</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Converting-a-char-variable-quot-00x-quot-to-a-numeric-variable/m-p/422539#M27208</link>
      <description>&lt;P&gt;Numeric variables in general do not ever contain a leading space. Do &lt;STRONG&gt;all &lt;/STRONG&gt; of these values end in X? If not then I doubt we will find a way to do this unless the numeric portion is unique for each character.&lt;/P&gt;
&lt;P&gt;I think what might help the most would be to run:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc sql;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select distinct variablenamegoeshere&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; from datasetnamegoeshere&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ;&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;P&gt;and post the result so we can see the range of values you may be dealing with.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Dec 2017 00:12:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Converting-a-char-variable-quot-00x-quot-to-a-numeric-variable/m-p/422539#M27208</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-12-20T00:12:58Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a char variable " 00x" to a numeric variable that looks the same: [blank sp</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Converting-a-char-variable-quot-00x-quot-to-a-numeric-variable/m-p/422540#M27209</link>
      <description>&lt;P&gt;I have applied the select distinct statement and I get the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;" 001"&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;" 002"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;" 003"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;" 004"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;" 005"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;" 006"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;" 007"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Dec 2017 00:21:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Converting-a-char-variable-quot-00x-quot-to-a-numeric-variable/m-p/422540#M27209</guid>
      <dc:creator>Rhein</dc:creator>
      <dc:date>2017-12-20T00:21:47Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a char variable " 00x" to a numeric variable that looks the same: [blank sp</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Converting-a-char-variable-quot-00x-quot-to-a-numeric-variable/m-p/422559#M27210</link>
      <description>&lt;P&gt;Apply a Z3 format. You don't get a leading space but you will get the leading zeroes.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you do really, really want a leading space, you can probably create a custom format.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;x = input(z, best12.);
format x z3.;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Dec 2017 00:43:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Converting-a-char-variable-quot-00x-quot-to-a-numeric-variable/m-p/422559#M27210</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-12-20T00:43:37Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a char variable " 00x" to a numeric variable that looks the same: [blank sp</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Converting-a-char-variable-quot-00x-quot-to-a-numeric-variable/m-p/422561#M27211</link>
      <description>&lt;P&gt;Thank you for your response. However, I&amp;nbsp;really want to put the leading space. Can you please explain to me how to create a custom format to be able to do it?&lt;/P&gt;</description>
      <pubDate>Wed, 20 Dec 2017 00:51:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Converting-a-char-variable-quot-00x-quot-to-a-numeric-variable/m-p/422561#M27211</guid>
      <dc:creator>Rhein</dc:creator>
      <dc:date>2017-12-20T00:51:39Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a char variable " 00x" to a numeric variable that looks the same: [blank sp</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Converting-a-char-variable-quot-00x-quot-to-a-numeric-variable/m-p/422565#M27212</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/183345"&gt;@Rhein&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Thank you for your response. However, I&amp;nbsp;really want to put the leading space. Can you please explain to me how to create a custom format to be able to do it?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It seems easier to stick with a character variable then, but a Picture format would be likely what you need.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www2.sas.com/proceedings/sugi31/243-31.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi31/243-31.pdf&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Dec 2017 01:22:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Converting-a-char-variable-quot-00x-quot-to-a-numeric-variable/m-p/422565#M27212</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-12-20T01:22:20Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a char variable " 00x" to a numeric variable that looks the same: [blank sp</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Converting-a-char-variable-quot-00x-quot-to-a-numeric-variable/m-p/422566#M27213</link>
      <description>&lt;P&gt;Just a heads up, Numbers, by default, are aligned right so you won’t see the space either unless you left align when testing. &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Dec 2017 01:25:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Converting-a-char-variable-quot-00x-quot-to-a-numeric-variable/m-p/422566#M27213</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-12-20T01:25:26Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a char variable " 00x" to a numeric variable that looks the same: [blank sp</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Converting-a-char-variable-quot-00x-quot-to-a-numeric-variable/m-p/422575#M27214</link>
      <description>&lt;P&gt;The request does not make any sense. Numbers do not contain spaces.&lt;/P&gt;
&lt;P&gt;If you want to put a space into a value then the variable is by definition a character string.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you trying to produce a report?&amp;nbsp; If you want to write space plus zero padded numbers then just do that.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;put ' ' x z3. ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Dec 2017 04:35:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Converting-a-char-variable-quot-00x-quot-to-a-numeric-variable/m-p/422575#M27214</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-12-20T04:35:05Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a char variable " 00x" to a numeric variable that looks the same: [blank sp</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Converting-a-char-variable-quot-00x-quot-to-a-numeric-variable/m-p/422577#M27215</link>
      <description>&lt;P&gt;Thanks, very interesting paper. I tried to apply it but still can’t manage ti keep a leading blank. Let me show you what i did:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt; &lt;STRONG&gt;format&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;picture formatpic (default=&lt;STRONG&gt;4&lt;/STRONG&gt;)&lt;/P&gt;&lt;P&gt;low-high='999'&lt;/P&gt;&lt;P&gt;(prefix=' ');&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;PROC&lt;/STRONG&gt; &lt;STRONG&gt;SQL&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;CREATE TABLE newtable AS&lt;/P&gt;&lt;P&gt;SELECT input_variable format=formatpic.&lt;/P&gt;&lt;P&gt;FROM input_table;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;QUIT&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;Where my input variable contained numeric values like: “003”&lt;/P&gt;&lt;P&gt;The idea was to add the prefix “ “, but it won’t add it. The way i test it is by exporting it to a .txt and seeing if the leading blank is there.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the paper, it says 0 print blanks. So, I also tried:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt; &lt;STRONG&gt;format&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;picture formatpic (default=&lt;STRONG&gt;4&lt;/STRONG&gt;)&lt;/P&gt;&lt;P&gt;low-high='0999';&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;PROC&lt;/STRONG&gt; &lt;STRONG&gt;SQL&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;CREATE TABLE newtable AS&lt;/P&gt;&lt;P&gt;SELECT input_variable format=formatpic.&lt;/P&gt;&lt;P&gt;FROM input_table;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;QUIT&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;Where my input variable contained numeric values like: “0003”. But when exporting again I don’t get my leading blank.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Dec 2017 02:38:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Converting-a-char-variable-quot-00x-quot-to-a-numeric-variable/m-p/422577#M27215</guid>
      <dc:creator>Rhein</dc:creator>
      <dc:date>2017-12-20T02:38:36Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a char variable " 00x" to a numeric variable that looks the same: [blank sp</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Converting-a-char-variable-quot-00x-quot-to-a-numeric-variable/m-p/422578#M27216</link>
      <description>&lt;P&gt;Yeah, I tried a bunch of things...couldn't get it either.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why do you need the blank? Perhaps there's another way to get the same behaviour.&amp;nbsp;&lt;BR /&gt;If you have a valid SAS license (likely with EG) I would consider asking tech support - or waiting to see if someone else can answer it :).&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Dec 2017 02:42:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Converting-a-char-variable-quot-00x-quot-to-a-numeric-variable/m-p/422578#M27216</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-12-20T02:42:15Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a char variable " 00x" to a numeric variable that looks the same: [blank sp</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Converting-a-char-variable-quot-00x-quot-to-a-numeric-variable/m-p/422582#M27217</link>
      <description>&lt;P&gt;Ok thank you very much for your help.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Dec 2017 03:04:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Converting-a-char-variable-quot-00x-quot-to-a-numeric-variable/m-p/422582#M27217</guid>
      <dc:creator>Rhein</dc:creator>
      <dc:date>2017-12-20T03:04:53Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a char variable " 00x" to a numeric variable that looks the same: [blank sp</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Converting-a-char-variable-quot-00x-quot-to-a-numeric-variable/m-p/422653#M27223</link>
      <description>&lt;P&gt;Your format does work:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
picture formatpic (default=4)
low-high='0999';
run;

data test;
length x1 $4;
x1 = put(9,formatpic4.);
x2 = put(x1,$hex8.);
run;

proc print data=test noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The resulting output is:&lt;/P&gt;
&lt;PRE&gt;x1        x2

009    20303039
&lt;/PRE&gt;
&lt;P&gt;so you can clearly see that the leading blank (hex 20) is there.&lt;/P&gt;
&lt;P&gt;Your problem comes when you export the string, instead of a formatted number. SAS will remove leading blanks from strings when writing them to a text file:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
set test;
file '$HOME/sascommunity/test.csv' dlm=',';
put x1 x2;
x3 = 9;
put x3 formatpic4.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The resulting file looks like this:&lt;/P&gt;
&lt;PRE&gt;009,20303039
 009&lt;/PRE&gt;
&lt;P&gt;The string has the leading blanks stripped, but the formatted numeric variable is written as you want.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Dec 2017 10:06:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Converting-a-char-variable-quot-00x-quot-to-a-numeric-variable/m-p/422653#M27223</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-12-20T10:06:05Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a char variable " 00x" to a numeric variable that looks the same: [blank sp</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Converting-a-char-variable-quot-00x-quot-to-a-numeric-variable/m-p/422783#M27246</link>
      <description>&lt;P&gt;Thanks, but how do I export it so that it keeps the blanks?&lt;/P&gt;</description>
      <pubDate>Wed, 20 Dec 2017 17:10:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Converting-a-char-variable-quot-00x-quot-to-a-numeric-variable/m-p/422783#M27246</guid>
      <dc:creator>Rhein</dc:creator>
      <dc:date>2017-12-20T17:10:32Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a char variable " 00x" to a numeric variable that looks the same: [blank sp</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Converting-a-char-variable-quot-00x-quot-to-a-numeric-variable/m-p/422788#M27250</link>
      <description>&lt;P&gt;Try a CHAR4 format, or if you want a space, why not explicitly export a space and the number using Z3 if that's your end goal?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Dec 2017 17:15:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Converting-a-char-variable-quot-00x-quot-to-a-numeric-variable/m-p/422788#M27250</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-12-20T17:15:15Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a char variable " 00x" to a numeric variable that looks the same: [blank sp</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Converting-a-char-variable-quot-00x-quot-to-a-numeric-variable/m-p/422832#M27261</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/183345"&gt;@Rhein&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Thanks, but how do I export it so that it keeps the blanks?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;How are you currently exporting the data? Provide code examples.&lt;/P&gt;
&lt;P&gt;There are multiple ways to send data elsewhere and each has advantages and disadvantages. Your specific method may be part of the issue, or the destination file, or how you examine the destination file (note Excel reformats lots of stuff without telling you).&lt;/P&gt;</description>
      <pubDate>Wed, 20 Dec 2017 18:52:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Converting-a-char-variable-quot-00x-quot-to-a-numeric-variable/m-p/422832#M27261</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-12-20T18:52:46Z</dc:date>
    </item>
  </channel>
</rss>

