<?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: How can I change position of character variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-change-position-of-character-variable/m-p/652433#M195873</link>
    <description>&lt;P&gt;I see no obvious pattern.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you explain how the characters are moved?&lt;/P&gt;
&lt;P&gt;In the last example the 2 has simply disappeared.&lt;/P&gt;
&lt;P&gt;Please put lot more effort explaining your needs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 02 Jun 2020 05:47:06 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2020-06-02T05:47:06Z</dc:date>
    <item>
      <title>How can I change position of character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-change-position-of-character-variable/m-p/651843#M195852</link>
      <description>&lt;P&gt;Hello Expert,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to swap the characters in a variable , how can I achieve this.&lt;/P&gt;&lt;P&gt;Sample i/p and o/p is as following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Input&lt;/TD&gt;&lt;TD&gt;Output&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Michael&lt;/TD&gt;&lt;TD&gt;Lhameci&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;A href="mailto:Jack@gmail.com" target="_blank" rel="noopener"&gt;Jack@gmail.com&lt;/A&gt;&lt;/TD&gt;&lt;TD&gt;&lt;A href="mailto:kcja@gmail.com" target="_blank" rel="noopener"&gt;kcja@gmail.com&lt;/A&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;AO987JJ&lt;/TD&gt;&lt;TD&gt;9J78JOA&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;9650234567&lt;/TD&gt;&lt;TD&gt;6953035947&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Fri, 29 May 2020 19:26:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-change-position-of-character-variable/m-p/651843#M195852</guid>
      <dc:creator>Trishjais</dc:creator>
      <dc:date>2020-05-29T19:26:05Z</dc:date>
    </item>
    <item>
      <title>Re: How can I change position of character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-change-position-of-character-variable/m-p/652433#M195873</link>
      <description>&lt;P&gt;I see no obvious pattern.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you explain how the characters are moved?&lt;/P&gt;
&lt;P&gt;In the last example the 2 has simply disappeared.&lt;/P&gt;
&lt;P&gt;Please put lot more effort explaining your needs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jun 2020 05:47:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-change-position-of-character-variable/m-p/652433#M195873</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-06-02T05:47:06Z</dc:date>
    </item>
    <item>
      <title>Re: How can I change position of character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-change-position-of-character-variable/m-p/652469#M195886</link>
      <description>&lt;P&gt;I suppose what you want is to have the letters randomly permuted. I think the easiest is to use PROC FCMP to write a function for that:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc fcmp outlib=work.funcs.permute;
  function permute(name$,type$) $200;
  length name2 $200 i j 8;
  do i=1 to length(name);
    j=rand('integer',length(name));
    substr(name2,i,1)=substr(name,j,1);
    substr(name,j)=substr(name,j+1);
    end;
  select(upcase(substr(type,1,1)));
    when('N') do; /* "name" or "nice", first letter capital */
      name2=lowcase(name2);
      substr(name2,1,1)=upcase(substr(name2,1,1));
      end;
    when(' ','I'); /* keep as is/irrelevant */
    when('U') name2=upcase(name2);
    when('L') name2=lowcase(name2);
    otherwise put 'WARNING: wrong type parameter' type=;
    end;
  return(name2);
  endsub;
run;
options cmplib=work.funcs;&amp;nbsp;/*&amp;nbsp;you&amp;nbsp;may&amp;nbsp;want&amp;nbsp;to&amp;nbsp;use&amp;nbsp;a&amp;nbsp;permanent&amp;nbsp;library&amp;nbsp;instead of WORK */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The function takes a random letter from the input, moves it to the output, discards it from the input, and repeats until input is empty. After that, the TYPE option is processed, see the code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With this data&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  length name surname $8 email $25 code $8;
  input name surname email code;
cards;
Jack Vance Jack@gmail.com A1245
Peter Sellers Peter@Pink.Panter.com B44444
;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;the function can be used like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  if _N_=1 then
    call streaminit(3);
  set have;
  name=permute(name,'N');
  surname=permute(surname,'N');
  mail_pref=permute(scan(Email,1,'@'),'N');
  substr(email,1,length(mail_pref))=mail_pref;
  drop mail_pref;
  code=permute(code,' ');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The STREAMINIT call makes the results repeatable (same result every time) by initiating the stream for the RAND calls. If you drop it, you will get different results every time you run the code.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jun 2020 10:09:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-change-position-of-character-variable/m-p/652469#M195886</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2020-06-02T10:09:06Z</dc:date>
    </item>
    <item>
      <title>Re: How can I change position of character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-change-position-of-character-variable/m-p/652501#M195906</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/242585"&gt;@Trishjais&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data input;&lt;BR /&gt;input lines$20.;&lt;BR /&gt;lines_=lines;&lt;/P&gt;&lt;P&gt;/*temporary replacements to avoid errors at macro processing*/&lt;BR /&gt;lines_=translate(lines, '2', '.');&lt;BR /&gt;lines_=translate(lines_, '1', '@');&lt;BR /&gt;lines;&lt;BR /&gt;Michael&lt;BR /&gt;Jack@gmail.com&lt;BR /&gt;AO987JJ&lt;BR /&gt;9650234567&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*dynamically create macro variables from the above data*/&lt;BR /&gt;data _null_;&lt;BR /&gt;set input;&lt;BR /&gt;call symputx("val"||left(_N_), lowcase(lines_));&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*empty data set to use at step 4 of macro def*/&lt;BR /&gt;data final;&lt;BR /&gt;length str $20;&lt;BR /&gt;str="";&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*use parmbuff to support random parameters at macro call*/&lt;BR /&gt;%macro result/parmbuff;&lt;BR /&gt;/*create length macro var based on the parameters passed to this macro def.&lt;BR /&gt;adding '1' is required since shuffled indices are followed by data set name*/&lt;BR /&gt;%let length = %eval(1+%sysfunc(countc(&amp;amp;syspbuff, ',')));&lt;BR /&gt;%let str=;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*loop to replace chars*/&lt;BR /&gt;%do i=2 %to &amp;amp;length;&lt;BR /&gt;/*extracting specified(random) chars from the original string*/&lt;BR /&gt;%let str = &amp;amp;str.%substr(%scan(&amp;amp;syspbuff, 1), %scan(&amp;amp;syspbuff, &amp;amp;i), 1);&lt;BR /&gt;%end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*storing each shuffled value in a separate data set*/&lt;BR /&gt;data ds_%scan(&amp;amp;syspbuff, 1);&lt;BR /&gt;/*optional length statement to avoid concatenation warnings*/&lt;BR /&gt;length str $20;&lt;BR /&gt;str="&amp;amp;str";&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*to join with other calls - step 4*/&lt;BR /&gt;data final(where=(not missing(str)));&lt;BR /&gt;set final ds_%scan(&amp;amp;syspbuff, 1);&lt;BR /&gt;run;&lt;BR /&gt;/*macro name after %mend is optional*/&lt;BR /&gt;%mend result;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*pass macro vars with desired shuffle order*/&lt;BR /&gt;/*semicolon at the end of macro call is optional*/&lt;BR /&gt;%result(&amp;amp;val1, 7, 1, 2, 3, 4, 5, 6)&lt;BR /&gt;%result(&amp;amp;val2, 4, 3, 1, 2, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14)&lt;BR /&gt;%result(&amp;amp;val3, 3, 6, 5, 4, 7, 2, 1)&lt;BR /&gt;%result(&amp;amp;val4, 2, 1, 3, 6, 4, 6, 3, 1, 7, 10)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;/*improvements*/&lt;BR /&gt;data final;&lt;BR /&gt;set final;&lt;BR /&gt;/*back to normal*/&lt;BR /&gt;str=translate(str, '@', '1');&lt;BR /&gt;str=translate(str, '.', '2');&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data output(drop=lines_ rename=(lines=input str=output));&lt;BR /&gt;/*make it side by side and some cosmetic changes*/&lt;BR /&gt;merge input final;&lt;BR /&gt;if findc(str, '@') then str=lowcase(str);&lt;BR /&gt;else if anydigit(str) then str=upcase(str);&lt;BR /&gt;else str=propcase(str);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*deleting extra data sets from work lib to save ram*/&lt;BR /&gt;proc datasets lib=work nolist;&lt;BR /&gt;save output;&lt;BR /&gt;quit;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jun 2020 11:35:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-change-position-of-character-variable/m-p/652501#M195906</guid>
      <dc:creator>VENKATAMAHESH</dc:creator>
      <dc:date>2020-06-02T11:35:59Z</dc:date>
    </item>
    <item>
      <title>Re: How can I change position of character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-change-position-of-character-variable/m-p/652504#M195907</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;You may check the attached solution for that problem.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jun 2020 13:29:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-change-position-of-character-variable/m-p/652504#M195907</guid>
      <dc:creator>VENKATAMAHESH</dc:creator>
      <dc:date>2020-06-02T13:29:46Z</dc:date>
    </item>
    <item>
      <title>Re: How can I change position of character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-change-position-of-character-variable/m-p/652513#M195911</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The REVERSE function sounds like all you need. I'm assuming there were a few typo's in your question and that you wanted a literal reverse of the character string presented.&lt;/P&gt;
&lt;P&gt;eg.&lt;/P&gt;
&lt;P&gt;Data _null_;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;cs = 'CharacterString';&lt;/P&gt;
&lt;P&gt;Put cs=;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;rcs = reverse (cs);&lt;/P&gt;
&lt;P&gt;put rcs=;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This will show in the log as:&lt;/P&gt;
&lt;P&gt;cs&amp;nbsp; = CharacterString&lt;/P&gt;
&lt;P&gt;rcs = gnirtSretcarahC&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note, if the value of the character string (cs) was 'Char&amp;nbsp;&amp;nbsp;&amp;nbsp; ' then the reversed string would be '&amp;nbsp;&amp;nbsp;&amp;nbsp; rahC' so you may want to use one of SAS's many blank removing functions to strip away the leading blanks - a simple use of the LEFT function here would remove the leading blanks.&amp;nbsp; e.g. LEFT(REVERSE(cs)) would give you 'rahC&amp;nbsp;&amp;nbsp;&amp;nbsp; '.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If this isn't what you require perhaps you can specify more detailed requirements?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BPD&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jun 2020 11:51:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-change-position-of-character-variable/m-p/652513#M195911</guid>
      <dc:creator>BPD</dc:creator>
      <dc:date>2020-06-02T11:51:39Z</dc:date>
    </item>
  </channel>
</rss>

