<?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: proc sql and trim in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-and-trim/m-p/378730#M91081</link>
    <description>&lt;P&gt;Many thanks for this.&lt;/P&gt;&lt;P&gt;Is it only because I declared the macrovariable before entering the PROC SQL?&lt;/P&gt;&lt;P&gt;It is strange this two ways of writing...&lt;/P&gt;</description>
    <pubDate>Mon, 24 Jul 2017 15:33:39 GMT</pubDate>
    <dc:creator>FP12</dc:creator>
    <dc:date>2017-07-24T15:33:39Z</dc:date>
    <item>
      <title>proc sql and trim</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-and-trim/m-p/378723#M91078</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I dcan't manage to use trim function in a proc sql, don't understand why.&lt;/P&gt;&lt;P&gt;I have a table A with a variable B which format is character(6):&lt;/P&gt;&lt;P&gt;I do this:&lt;/P&gt;&lt;PRE&gt;%global b;

PROC SQL NOPRINT;
	SELECT TRIM(B) INTO :b
	FROM A
	WHERE ROW_NUMBER = 1;
QUIT;
%put ___&amp;amp;b.___;&lt;/PRE&gt;&lt;P&gt;The result in the log is:&lt;/P&gt;&lt;PRE&gt;___A1    ___&lt;/PRE&gt;&lt;P&gt;I surely miss something, can you help me finding it?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jul 2017 15:22:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-and-trim/m-p/378723#M91078</guid>
      <dc:creator>FP12</dc:creator>
      <dc:date>2017-07-24T15:22:34Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql and trim</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-and-trim/m-p/378727#M91079</link>
      <description>&lt;P&gt;When creating macro variables you need the TRIMMED option.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%global b;

PROC SQL NOPRINT;
	SELECT B INTO :b TRIMMED
	FROM A
	WHERE ROW_NUMBER = 1;
QUIT;
%put ___&amp;amp;b.___;&lt;/PRE&gt;</description>
      <pubDate>Mon, 24 Jul 2017 15:30:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-and-trim/m-p/378727#M91079</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-07-24T15:30:12Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql and trim</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-and-trim/m-p/378728#M91080</link>
      <description>&lt;P&gt;Really, as:&lt;/P&gt;
&lt;PRE&gt;proc sql noprint;  
  select trim(" abc    ") into :r from sashelp.class where name="Alfred";
quit;
%put ___&amp;amp;r.___;
&lt;/PRE&gt;
&lt;P&gt;Works fine. &amp;nbsp;You may also be better off using strip() function rather than trim()&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jul 2017 15:32:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-and-trim/m-p/378728#M91080</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-07-24T15:32:44Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql and trim</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-and-trim/m-p/378730#M91081</link>
      <description>&lt;P&gt;Many thanks for this.&lt;/P&gt;&lt;P&gt;Is it only because I declared the macrovariable before entering the PROC SQL?&lt;/P&gt;&lt;P&gt;It is strange this two ways of writing...&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jul 2017 15:33:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-and-trim/m-p/378730#M91081</guid>
      <dc:creator>FP12</dc:creator>
      <dc:date>2017-07-24T15:33:39Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql and trim</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-and-trim/m-p/378731#M91082</link>
      <description>&lt;P&gt;SAS stores character variables as fixed length variables. Since you didn't tell SQL what length to make the new variable you created with the TRIM() function call its best guess was to make it the same length as the variable going into the TRIM() function. So then when you pushed the value into a macro variable it included the spaces needed to pad the trimmed value back out to the full length of the variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use the TRIMMED keyword as part of the INTO clause to remove the trailing spaces.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select b 
  into :b trimmed
  from a
  where row_number = 1
;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 24 Jul 2017 15:34:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-and-trim/m-p/378731#M91082</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-07-24T15:34:39Z</dc:date>
    </item>
  </channel>
</rss>

