<?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 Trimming a Character variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Trimming-a-Character-variable/m-p/144454#M28828</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a character variable that is formatted with a length of 36.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This variable contains department names of varying lengths, from 9 all the way to, well, 36.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I create different data sets from a subset of a larger data set using variable (each department goes into its own data set).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The variable stays character (obviously) with a length of 36, but I need to remove the trailing blanks from all of those that are less than 36 length.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've tried trim / strip / compress - none of these change the format length of the variable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I can use put, except then I would have to input all of the different lengths.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What I would like to do (if possible) is assign the length to a macro variable and then somehow use that in the put statement, but it just isn't working (possible for a good reason).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is what I have tried along this line:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let test = %length(dept); /*&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dept is the variable name, and I want to count the length of it not including trailing spaces (spaced between words is okay)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; */&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the case of Dept = Visual Arts, I want &amp;amp;test to resolve to 11, instead it resolves to 4 - the length of dept.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any help would be greatly appreciated.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 14 Nov 2013 20:37:57 GMT</pubDate>
    <dc:creator>GregG</dc:creator>
    <dc:date>2013-11-14T20:37:57Z</dc:date>
    <item>
      <title>Trimming a Character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trimming-a-Character-variable/m-p/144454#M28828</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a character variable that is formatted with a length of 36.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This variable contains department names of varying lengths, from 9 all the way to, well, 36.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I create different data sets from a subset of a larger data set using variable (each department goes into its own data set).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The variable stays character (obviously) with a length of 36, but I need to remove the trailing blanks from all of those that are less than 36 length.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've tried trim / strip / compress - none of these change the format length of the variable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I can use put, except then I would have to input all of the different lengths.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What I would like to do (if possible) is assign the length to a macro variable and then somehow use that in the put statement, but it just isn't working (possible for a good reason).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is what I have tried along this line:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let test = %length(dept); /*&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dept is the variable name, and I want to count the length of it not including trailing spaces (spaced between words is okay)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; */&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the case of Dept = Visual Arts, I want &amp;amp;test to resolve to 11, instead it resolves to 4 - the length of dept.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any help would be greatly appreciated.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Nov 2013 20:37:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trimming-a-Character-variable/m-p/144454#M28828</guid>
      <dc:creator>GregG</dc:creator>
      <dc:date>2013-11-14T20:37:57Z</dc:date>
    </item>
    <item>
      <title>Re: Trimming a Character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trimming-a-Character-variable/m-p/144455#M28829</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That's because its look at the word "DEPT" not the variable dept.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I'm not quite understanding though. One variable can have only one format for all the observations, and one length for the variable, which is the maximum length. The LENGTH function will take the length of the specific observation.&lt;/P&gt;&lt;P&gt;VLENGTH function returns the length of the variable&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LENGTHC - returns length of variable with trailing blanks&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There's some other length functions as well. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So basically, what are you trying to do and why &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Nov 2013 20:46:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trimming-a-Character-variable/m-p/144455#M28829</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2013-11-14T20:46:54Z</dc:date>
    </item>
    <item>
      <title>Re: Trimming a Character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trimming-a-Character-variable/m-p/144456#M28830</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You may be misunderstanding what the FORMAT means. It basically says, with a $36. format, to display the variable upto 36 characters. Format applies to the description of the Variable, not the individual values. If you have run strip on the variable there are no longer any trailing blanks, if there ever were any.&lt;/P&gt;&lt;P&gt;See what happens when you do something like this to see the behavior of Format:&lt;/P&gt;&lt;P&gt;proc print data=yourdatasetname;&lt;/P&gt;&lt;P&gt;var dept;&lt;/P&gt;&lt;P&gt;format dept $4.;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also the reason %let test = %length(dept); Resolves to 4 is that macro functions look at the text provided, in this cas dept, NOT the variable. Use the length in datastep to confirm that&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; test= length(dept); /* dept is a varaible in have. Length will not return the length */&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;proc print; var dept test;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;also try this;&lt;/P&gt;&lt;P&gt;Data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; x= ' a string with trailling blanks&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;&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; ';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; y=length(x);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; put y=;&lt;/P&gt;&lt;P&gt;run; /*look in the log for output to see how the length function deals with trailing blanks*/&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Nov 2013 20:53:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trimming-a-Character-variable/m-p/144456#M28830</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2013-11-14T20:53:00Z</dc:date>
    </item>
    <item>
      <title>Re: Trimming a Character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trimming-a-Character-variable/m-p/144457#M28831</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This works but not too elegant:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;/TD&gt;&lt;TD&gt;data visual_arts ;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set have (where = (dept = 'Visual Arts')) ;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&amp;nbsp; &lt;/TD&gt;&lt;TD&gt; call symput('dlen',length(dept)) ;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; run ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; data visual_arts (drop = dept) ;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&amp;nbsp; &lt;/TD&gt;&lt;TD&gt; length department $&amp;amp;dlen ;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set visual_arts ;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&amp;nbsp; &lt;/TD&gt;&lt;TD&gt; department = dept ;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; run ;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Nov 2013 20:59:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trimming-a-Character-variable/m-p/144457#M28831</guid>
      <dc:creator>SteveNZ</dc:creator>
      <dc:date>2013-11-14T20:59:36Z</dc:date>
    </item>
    <item>
      <title>Re: Trimming a Character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trimming-a-Character-variable/m-p/144458#M28832</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How about something like this based on your idea &lt;A __default_attr="807252" __jive_macro_name="user" class="jive_macro jive_macro_user" href="https://communities.sas.com/"&gt;&lt;/A&gt;&lt;/P&gt;&lt;DIV style="font-family: Courier New; font-size: 11pt;"&gt;&lt;SPAN style="color: #000080; background-color: #ffffff;"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt; have;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;input&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt; dept &amp;amp;&lt;/SPAN&gt;&lt;SPAN style="color: #008080; background-color: #ffffff;"&gt;$32.&lt;/SPAN&gt;; &lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;cards&lt;/SPAN&gt;; &lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffc0;"&gt;Visual Arts&lt;BR /&gt;Math&lt;BR /&gt;History&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;;;;;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #000080; background-color: #ffffff;"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/SPAN&gt;; &lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;%let&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt; dept = Visual Arts;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000080; background-color: #ffffff;"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt; visual_arts;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;length&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt; dept $&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;%length&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;(&amp;amp;dept);&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;set&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt; have(&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;where&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;=(dept eq &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;%sysfunc&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;(quote(&amp;amp;dept))));&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #000080; background-color: #ffffff;"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/SPAN&gt;; &lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000080; background-color: #ffffff;"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/SPAN&gt; &lt;SPAN style="color: #000080; background-color: #ffffff;"&gt;&lt;STRONG&gt;print&lt;/STRONG&gt;&lt;/SPAN&gt;; &lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #000080; background-color: #ffffff;"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/SPAN&gt;; &lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: data _null_&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Nov 2013 21:11:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trimming-a-Character-variable/m-p/144458#M28832</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2013-11-14T21:11:36Z</dc:date>
    </item>
    <item>
      <title>Re: Trimming a Character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trimming-a-Character-variable/m-p/144459#M28833</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Well, after much playing, I got something similar to what SteveNZ suggested, but even more clunky.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is the the gist of the program: An academic program review for all departments at my university.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It is the same report, for all of the different departments, so we are using macros to program the logic once, and then run for the various departments (based on Major Codes, not department names - this wasn't my call).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The report would be output using a file="Academic_Program_Review_for_&amp;amp;Year._&amp;amp;Department..rtf"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That last variable would have a varying degree of spaces depending on the department name, for instance, Visual Arts would come with 24 spaces before the .rtf&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My boss would not accept that, and it is their program (I'm just attempting to assist on certain aspects).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So this is what I came up with:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;IF MAJOR_COHORT IN &amp;amp;major_list&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;dept1=TRIM(put(major_cohort,&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: teal; background: white;"&gt;$dept_INV.&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;)); /*Because of &amp;amp;dept_inv., Dept1 has a length of $36 regardless of actual length of the current department name, trim does nothing here*/&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;CALL SYMPUT (&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;"DEPARTMENT1"&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;,DEPT1);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /*Create a variable of the department name (this was previously used in the file name above*/&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;%let&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; test = &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;%length&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;(&amp;amp;department1);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /*Use the above variable to count the length of the current department name, Visual Arts = 11*/&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;DEPT = put(DEPT1,$&amp;amp;&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: teal; background: white;"&gt;test.&lt;STRONG&gt;.&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;);&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; /*Create a new DEPT with the length of the current Department, Visual Arts would be 11*/&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;CALL SYMPUT (&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;"DEPARTMENT"&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;,DEPT);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /*Create a new variable for use in the .rtf file name (see above) without the trailing spaces/blanks*/&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;Thank you all for your time helping me.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Nov 2013 21:12:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trimming-a-Character-variable/m-p/144459#M28833</guid>
      <dc:creator>GregG</dc:creator>
      <dc:date>2013-11-14T21:12:16Z</dc:date>
    </item>
    <item>
      <title>Re: Trimming a Character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trimming-a-Character-variable/m-p/144460#M28834</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Use %trim instead, either in string or create a new macro variable, see below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data class;&lt;/P&gt;&lt;P&gt;set sashelp.class;&lt;/P&gt;&lt;P&gt;length1=length(name);&lt;/P&gt;&lt;P&gt;length2=lengthc(name);&lt;/P&gt;&lt;P&gt;length3=vlength(name);&lt;/P&gt;&lt;P&gt;if name='Jane' then call symput('var1', name);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let var2=%trim(&amp;amp;var1);&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;string1="put this is my &amp;amp;var1. with extra spaces";&lt;/P&gt;&lt;P&gt;string2="this is my %trim(&amp;amp;var1.) with no extra spaces";&lt;/P&gt;&lt;P&gt;string3="this is my &amp;amp;var2. with no extra spaces";&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;put "String1:" string1;&lt;/P&gt;&lt;P&gt;put "String2:" string2;&lt;/P&gt;&lt;P&gt;put "String3:" string3;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;682&amp;nbsp; data _null_;&lt;/P&gt;&lt;P&gt;683&lt;/P&gt;&lt;P&gt;684&amp;nbsp; string1="put this is my &amp;amp;var1. with extra spaces";&lt;/P&gt;&lt;P&gt;685&amp;nbsp; string2="this is my %trim(&amp;amp;var1.) with no extra spaces";&lt;/P&gt;&lt;P&gt;686&amp;nbsp; string3="this is my &amp;amp;var2. with no extra spaces";&lt;/P&gt;&lt;P&gt;687&lt;/P&gt;&lt;P&gt;688&amp;nbsp; put "String1:" string1;&lt;/P&gt;&lt;P&gt;689&amp;nbsp; put "String2:" string2;&lt;/P&gt;&lt;P&gt;690&amp;nbsp; put "String3:" string3;&lt;/P&gt;&lt;P&gt;691&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;String1:put this is my Jane&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; with extra spaces&lt;/P&gt;&lt;P&gt;String2:this is my Jane with no extra spaces&lt;/P&gt;&lt;P&gt;String3:this is my Jane with no extra spaces&lt;/P&gt;&lt;P&gt;NOTE: DATA statement used (Total process time):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; real time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.00 seconds&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cpu time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.00 seconds&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Nov 2013 21:20:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trimming-a-Character-variable/m-p/144460#M28834</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2013-11-14T21:20:30Z</dc:date>
    </item>
    <item>
      <title>Re: Trimming a Character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trimming-a-Character-variable/m-p/144461#M28835</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you are generating a macro variable from a data set variable use CALL SYMPUTX to have the value automatically trimmed.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: black; background-color: white;"&gt;CALL SYMPUTX (&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: purple; background-color: white;"&gt;"DEPARTMENT1"&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: black; background-color: white;"&gt;,DEPT1);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: black; background-color: white;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: black; background-color: white;"&gt;You have confused the order of macro language execution and the compiled SAS code that the macro language has generated. So your %LET statement in the middle of a data step actually is evaluated BEFORE the data step starts.&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Nov 2013 21:43:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trimming-a-Character-variable/m-p/144461#M28835</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-11-14T21:43:27Z</dc:date>
    </item>
    <item>
      <title>Re: Trimming a Character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trimming-a-Character-variable/m-p/144462#M28836</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Tom,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm not doubting you at all - but perhaps I am misunderstanding you. The code that I posted above works, the %let statement in the middle works for each department length correctly.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I will definitely try call symputx to get rid of clutter.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for your time.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now I have to find out if it is possible to append a new excel sheet to an existing excel workbook, but that is a question for another area.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Call Symputx worked perfectly - in fact, it's a bit hilarious as originally I had that line (without the x) and it was causing the spaces. I expanded to 5 lines, then 3 lines (based on Reeza's %trim suggestion) and now back to the original 2 lines, except with the x.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Nov 2013 22:00:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trimming-a-Character-variable/m-p/144462#M28836</guid>
      <dc:creator>GregG</dc:creator>
      <dc:date>2013-11-14T22:00:04Z</dc:date>
    </item>
    <item>
      <title>Re: Trimming a Character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trimming-a-Character-variable/m-p/144463#M28837</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;To see the timing run something like this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let name=;&lt;/P&gt;&lt;P&gt;%put Before = &amp;amp;name;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set sashelp.class (obs=1);&lt;/P&gt;&lt;P&gt;&amp;nbsp; call symputx('name',name);&lt;/P&gt;&lt;P&gt;%put During = &amp;amp;name;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%put After = &amp;amp;name;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Nov 2013 00:03:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trimming-a-Character-variable/m-p/144463#M28837</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-11-15T00:03:40Z</dc:date>
    </item>
  </channel>
</rss>

