<?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 PROC TRANSPOSE: Blanks removed if using PREFIX statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROC-TRANSPOSE-Blanks-removed-if-using-PREFIX-statement/m-p/794194#M254636</link>
    <description>&lt;P&gt;I have the following two codes:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc transpose data=rank_score out=rank_score_tr
(drop=_name_ _suffix_);
by url;
id _term_;
var N;
run;

option VALIDVARNAME=ANY;

proc transpose data=rank_score out=rank_score_tr2
(drop=_name_ _suffix_) prefix=rank_ ;
by url;
id _term_;
var rankcount;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The dataset include in the _term_ column combinations of maximum two letters, with the chance of having both "a" and " a" or "a ", including spaces.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The first transpose works like a charm.&lt;/P&gt;&lt;P&gt;The second, adding prefix, seems compressing the blanks and provide error of duplicate at BY level&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I checked the documentation but no track of having this kind of compression using the prefix statement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyone knowing why it is happening and how to stop the space compression?&lt;/P&gt;</description>
    <pubDate>Thu, 03 Feb 2022 11:38:38 GMT</pubDate>
    <dc:creator>dcortell</dc:creator>
    <dc:date>2022-02-03T11:38:38Z</dc:date>
    <item>
      <title>PROC TRANSPOSE: Blanks removed if using PREFIX statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-TRANSPOSE-Blanks-removed-if-using-PREFIX-statement/m-p/794194#M254636</link>
      <description>&lt;P&gt;I have the following two codes:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc transpose data=rank_score out=rank_score_tr
(drop=_name_ _suffix_);
by url;
id _term_;
var N;
run;

option VALIDVARNAME=ANY;

proc transpose data=rank_score out=rank_score_tr2
(drop=_name_ _suffix_) prefix=rank_ ;
by url;
id _term_;
var rankcount;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The dataset include in the _term_ column combinations of maximum two letters, with the chance of having both "a" and " a" or "a ", including spaces.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The first transpose works like a charm.&lt;/P&gt;&lt;P&gt;The second, adding prefix, seems compressing the blanks and provide error of duplicate at BY level&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I checked the documentation but no track of having this kind of compression using the prefix statement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyone knowing why it is happening and how to stop the space compression?&lt;/P&gt;</description>
      <pubDate>Thu, 03 Feb 2022 11:38:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-TRANSPOSE-Blanks-removed-if-using-PREFIX-statement/m-p/794194#M254636</guid>
      <dc:creator>dcortell</dc:creator>
      <dc:date>2022-02-03T11:38:38Z</dc:date>
    </item>
    <item>
      <title>Re: PROC TRANSPOSE: Blanks removed if using PREFIX statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-TRANSPOSE-Blanks-removed-if-using-PREFIX-statement/m-p/794198#M254637</link>
      <description>Using suffix instead of prefix seems to work.&lt;BR /&gt;&lt;BR /&gt;Although you produce two columns basically indistinguishable. Wouldn't it be better to replace the blank in the first place, i. e. by an underscore? But you probably have your reasons.</description>
      <pubDate>Thu, 03 Feb 2022 12:05:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-TRANSPOSE-Blanks-removed-if-using-PREFIX-statement/m-p/794198#M254637</guid>
      <dc:creator>msauer</dc:creator>
      <dc:date>2022-02-03T12:05:25Z</dc:date>
    </item>
    <item>
      <title>Re: PROC TRANSPOSE: Blanks removed if using PREFIX statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-TRANSPOSE-Blanks-removed-if-using-PREFIX-statement/m-p/794199#M254638</link>
      <description>&lt;P&gt;Can't do that as we can also have "_a" or " a" and both of them must count as separate variables&lt;/P&gt;</description>
      <pubDate>Thu, 03 Feb 2022 12:11:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-TRANSPOSE-Blanks-removed-if-using-PREFIX-statement/m-p/794199#M254638</guid>
      <dc:creator>dcortell</dc:creator>
      <dc:date>2022-02-03T12:11:46Z</dc:date>
    </item>
    <item>
      <title>Re: PROC TRANSPOSE: Blanks removed if using PREFIX statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-TRANSPOSE-Blanks-removed-if-using-PREFIX-statement/m-p/794200#M254639</link>
      <description>What about enclosing the _term_ column by an underscore before doing the transpose ...?</description>
      <pubDate>Thu, 03 Feb 2022 12:13:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-TRANSPOSE-Blanks-removed-if-using-PREFIX-statement/m-p/794200#M254639</guid>
      <dc:creator>msauer</dc:creator>
      <dc:date>2022-02-03T12:13:00Z</dc:date>
    </item>
    <item>
      <title>Re: PROC TRANSPOSE: Blanks removed if using PREFIX statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-TRANSPOSE-Blanks-removed-if-using-PREFIX-statement/m-p/794202#M254640</link>
      <description>&lt;P&gt;Actually I could solve adding the prefix generating a new variable and then transposing it as ID, but I was curios to understand why the transpose via prefix was generating this kind of behavior&lt;/P&gt;</description>
      <pubDate>Thu, 03 Feb 2022 12:24:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-TRANSPOSE-Blanks-removed-if-using-PREFIX-statement/m-p/794202#M254640</guid>
      <dc:creator>dcortell</dc:creator>
      <dc:date>2022-02-03T12:24:31Z</dc:date>
    </item>
    <item>
      <title>Re: PROC TRANSPOSE: Blanks removed if using PREFIX statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-TRANSPOSE-Blanks-removed-if-using-PREFIX-statement/m-p/794206#M254643</link>
      <description>&lt;P&gt;Your second statement says you want to create one row per url and use the content of _term_ as new variables (named rank_A_A and rank_A) and the value of these variables has to be rankcount.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So,&lt;/P&gt;
&lt;P&gt;first, since "rank_A A" is not a valid variable name, SAS inserts an underscores to match the &lt;A href="https://v8doc.sas.com/sashtml/lgref/z1031056.htm#:~:text=SAS%20variable%20names%20may%20be,name%20may%20not%20contain%20blanks." target="_blank" rel="noopener"&gt;restrictions&lt;/A&gt;&amp;nbsp;and creates 'rank_A_A'&lt;/P&gt;
&lt;P&gt;second, if for a same url you have more than one time the same _term_ SAS will not know which of the rankcount values it has to put as new value of the rank_ variables. That's why you get the errors in your log. Your combination of by group and id group needs to be unique.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Consider posting a simple example of the data you have and what you'd expect&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Feb 2022 12:37:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-TRANSPOSE-Blanks-removed-if-using-PREFIX-statement/m-p/794206#M254643</guid>
      <dc:creator>Oligolas</dc:creator>
      <dc:date>2022-02-03T12:37:29Z</dc:date>
    </item>
    <item>
      <title>Re: PROC TRANSPOSE: Blanks removed if using PREFIX statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-TRANSPOSE-Blanks-removed-if-using-PREFIX-statement/m-p/794227#M254657</link>
      <description>As stated in the description proc transpose accept blanks in the variable name, it is only when prefix it is used that the blanks are removed, and this cause the proc to detect by and id groups duplication, where there are none. As example I have provided the above where for the same url (by) I have to value in the ID group " a" and "a", first including blank, second without blank. Underscore can't be used as there could be also values like "_a" in the id group. In the end the only solution I found to keep the blanks in the variable name by adding also a prefix is to generate a new variable column with the desired prefix BEFORE the proc transpose.</description>
      <pubDate>Thu, 03 Feb 2022 15:04:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-TRANSPOSE-Blanks-removed-if-using-PREFIX-statement/m-p/794227#M254657</guid>
      <dc:creator>dcortell</dc:creator>
      <dc:date>2022-02-03T15:04:06Z</dc:date>
    </item>
    <item>
      <title>Re: PROC TRANSPOSE: Blanks removed if using PREFIX statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-TRANSPOSE-Blanks-removed-if-using-PREFIX-statement/m-p/794432#M254735</link>
      <description>&lt;P&gt;oh yeah I see, you use VALIDVARNAME=ANY and get the results you want.&lt;/P&gt;
&lt;P&gt;I acknowledge your trick works.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As far as I know, this means you have to work with SAS named literals if you further want to proceed the variables.&lt;/P&gt;
&lt;P&gt;I'd get chills just thinking about it but I haven't the big picture of what you're trying to do and it's your code in the end.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test1;
length url $30 _term_ $10;
url='kjahskdhfkh';
_term_=' A A';
rankcount=1;
output;
url='kjahskdhfkh';
_term_='A A';
rankcount=2;
output;
url='kjahskdhfkh';
_term_='A';
rankcount=3;
output;
url='kjahskdhfkh';
_term_=' A';
rankcount=1;
output;
url='kjahskdhfkh';
_term_='_A';
rankcount=1;
output;
run;

data test1;
   set test1;
   _term_=cat('_',_term_);
run;

option VALIDVARNAME=ANY;

proc transpose data=test1 out=test2
(drop=_name_ _suffix_) prefix=rank_ ;
by url;
id _term_;
var rankcount;
run;

data test3;
   set test2;
   'rank__ A A'n='rank__ A A'n+100;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Feb 2022 09:27:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-TRANSPOSE-Blanks-removed-if-using-PREFIX-statement/m-p/794432#M254735</guid>
      <dc:creator>Oligolas</dc:creator>
      <dc:date>2022-02-04T09:27:58Z</dc:date>
    </item>
  </channel>
</rss>

