<?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: Removing permanently spaces in the variables in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Removing-permanently-spaces-in-the-variables/m-p/55538#M15470</link>
    <description>Hi R_Win,&lt;BR /&gt;
&lt;BR /&gt;
the following code queries sashelp.vcolumn to get the variable names and call execute to create a proc datasets with the rename statment for all variables.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data _null_;&lt;BR /&gt;
	set sashelp.vcolumn(&lt;BR /&gt;
			keep= Name LibName MemName&lt;BR /&gt;
			rename= (Name = OldName) &lt;BR /&gt;
			where= (Libname='WORK' and MemName = 'A')&lt;BR /&gt;
		) end= last;&lt;BR /&gt;
	length NewName $ 32;&lt;BR /&gt;
&lt;BR /&gt;
	if _n_ = 1 then do;&lt;BR /&gt;
		call execute('proc datasets library=work nolist;');&lt;BR /&gt;
		call execute('modify a;');&lt;BR /&gt;
		call execute('rename ');&lt;BR /&gt;
	end;&lt;BR /&gt;
&lt;BR /&gt;
	NewName = compress(OldName, ' ');&lt;BR /&gt;
	OldName = cats("'", OldName, "'n");&lt;BR /&gt;
&lt;BR /&gt;
	call execute(trim(OldName) !! ' = ' !! trim(NewName));&lt;BR /&gt;
&lt;BR /&gt;
	if last then do;&lt;BR /&gt;
		call execute(';');&lt;BR /&gt;
		call execute('run;');&lt;BR /&gt;
	end;&lt;BR /&gt;
run;[/pre]</description>
    <pubDate>Tue, 28 Dec 2010 08:14:00 GMT</pubDate>
    <dc:creator>andreas_lds</dc:creator>
    <dc:date>2010-12-28T08:14:00Z</dc:date>
    <item>
      <title>Removing permanently spaces in the variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Removing-permanently-spaces-in-the-variables/m-p/55537#M15469</link>
      <description>Hi i am having sas dataset in that i am having 200-300 variables having spaces&lt;BR /&gt;
how can i remove all the spaces in the variables in that dataset permanently;&lt;BR /&gt;
&lt;BR /&gt;
data a;&lt;BR /&gt;
input 'id   1'n 'id         2' n-------------------------- 'id            200'n;&lt;BR /&gt;
run;</description>
      <pubDate>Tue, 28 Dec 2010 07:32:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Removing-permanently-spaces-in-the-variables/m-p/55537#M15469</guid>
      <dc:creator>R_Win</dc:creator>
      <dc:date>2010-12-28T07:32:12Z</dc:date>
    </item>
    <item>
      <title>Re: Removing permanently spaces in the variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Removing-permanently-spaces-in-the-variables/m-p/55538#M15470</link>
      <description>Hi R_Win,&lt;BR /&gt;
&lt;BR /&gt;
the following code queries sashelp.vcolumn to get the variable names and call execute to create a proc datasets with the rename statment for all variables.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data _null_;&lt;BR /&gt;
	set sashelp.vcolumn(&lt;BR /&gt;
			keep= Name LibName MemName&lt;BR /&gt;
			rename= (Name = OldName) &lt;BR /&gt;
			where= (Libname='WORK' and MemName = 'A')&lt;BR /&gt;
		) end= last;&lt;BR /&gt;
	length NewName $ 32;&lt;BR /&gt;
&lt;BR /&gt;
	if _n_ = 1 then do;&lt;BR /&gt;
		call execute('proc datasets library=work nolist;');&lt;BR /&gt;
		call execute('modify a;');&lt;BR /&gt;
		call execute('rename ');&lt;BR /&gt;
	end;&lt;BR /&gt;
&lt;BR /&gt;
	NewName = compress(OldName, ' ');&lt;BR /&gt;
	OldName = cats("'", OldName, "'n");&lt;BR /&gt;
&lt;BR /&gt;
	call execute(trim(OldName) !! ' = ' !! trim(NewName));&lt;BR /&gt;
&lt;BR /&gt;
	if last then do;&lt;BR /&gt;
		call execute(';');&lt;BR /&gt;
		call execute('run;');&lt;BR /&gt;
	end;&lt;BR /&gt;
run;[/pre]</description>
      <pubDate>Tue, 28 Dec 2010 08:14:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Removing-permanently-spaces-in-the-variables/m-p/55538#M15470</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2010-12-28T08:14:00Z</dc:date>
    </item>
    <item>
      <title>Re: Removing permanently spaces in the variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Removing-permanently-spaces-in-the-variables/m-p/55539#M15471</link>
      <description>Also, consider using an ARRAY approach as shown below:&lt;BR /&gt;
&lt;BR /&gt;
DATA A;&lt;BR /&gt;
SET A;&lt;BR /&gt;
ARRAY ALLCHARVARS (*) $ _CHARACTER_;&lt;BR /&gt;
DO I=1 TO DIM(ALLCHARVARS);&lt;BR /&gt;
  ALLCHARVARS(I) = COMPRESS( ALLCHARVARS(I) );&lt;BR /&gt;
END;&lt;BR /&gt;
RUN;&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Tue, 28 Dec 2010 11:53:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Removing-permanently-spaces-in-the-variables/m-p/55539#M15471</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-12-28T11:53:46Z</dc:date>
    </item>
    <item>
      <title>Re: Removing permanently spaces in the variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Removing-permanently-spaces-in-the-variables/m-p/55540#M15472</link>
      <description>Hi&lt;BR /&gt;
&lt;BR /&gt;
Try:&lt;BR /&gt;
&lt;BR /&gt;
array charvars (*) _character_;&lt;BR /&gt;
do i=1 to dim(charvars);&lt;BR /&gt;
  charvars(i)=compress(charvars(i));&lt;BR /&gt;
end;&lt;BR /&gt;
drop i;&lt;BR /&gt;
&lt;BR /&gt;
HTH&lt;BR /&gt;
Patrick</description>
      <pubDate>Tue, 28 Dec 2010 11:57:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Removing-permanently-spaces-in-the-variables/m-p/55540#M15472</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2010-12-28T11:57:20Z</dc:date>
    </item>
    <item>
      <title>Re: Removing permanently spaces in the variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Removing-permanently-spaces-in-the-variables/m-p/55541#M15473</link>
      <description>R_Win  &lt;BR /&gt;
  &lt;BR /&gt;
unless you define shorter lengths to reduce the size of variables, the data set will be the same size even if you compress to reduce multiple blanks to one. The compress of a variable just moves blanks from the middle to the end of the variable.&lt;BR /&gt;
Except, using an option I didn't see recommended by SBB or Patrick, you can get sas to write the rows with compression, like&lt;BR /&gt;
data reduced&lt;B&gt;(compress=yes)&lt;/B&gt; ;&lt;BR /&gt;
set original ;&lt;BR /&gt;
array chrs _character_ ;&lt;BR /&gt;
do over chrs ;&lt;BR /&gt;
chrs= compbl( chrs ) ;&lt;BR /&gt;
end ;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Of course, that interprets the objective as referring to content of variables.&lt;BR /&gt;
 &lt;BR /&gt;
If you refer to the blanks in variable names (not values) adopt the solution from andreas_lds &lt;BR /&gt;
 &lt;BR /&gt;
peterc</description>
      <pubDate>Tue, 04 Jan 2011 14:04:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Removing-permanently-spaces-in-the-variables/m-p/55541#M15473</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2011-01-04T14:04:49Z</dc:date>
    </item>
  </channel>
</rss>

