<?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 Tranwrd on multiple variables within a loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Tranwrd-on-multiple-variables-within-a-loop/m-p/270930#M53884</link>
    <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the following code in SAS D.I studio.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My objective is to run multiple tranwrd statements (only 2 shown out of ~50) against a number of variables within a dataset. (Please note the Tranwrd 'replace' values have just been used for illustrative purposes).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options symbolgen mprint mlogic;


data table_x;
	input first_name :$10. location:$10. junk:$10.;
	datalines;
	Rober$t L$ee£ds A£BCD
	Chris£topher M$£chester A$$BCD
	Marti$n Y$o£rk ABC£D
;
run;


%macro bulk(column);

data staging_x;
	set table_x;
	&amp;amp;column. = tranwrd(&amp;amp;column.,'$','Y');
	&amp;amp;column. = tranwrd(&amp;amp;column.,'£','X');
run;

proc sql;
create table table_y as select *
	from &amp;amp;syslast.;
quit;

%mend bulk;


%macro run_now;

proc contents
	data = work.table_x;
	out = work.table_output;
quit;

proc sql noprint;
	select distinct NAME into %nrstr(:name1-:name999) from work.table_output;
quit;

data _null_;
	%do i=1 %to &amp;amp;sqlobs.;
	%let Var = &amp;amp;&amp;amp;name&amp;amp;i;
	%put Var = &amp;amp;Var.;

	%bulk(&amp;amp;Var.);

	%end
	
run;
;
%mend run_now;

%run_now;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The issue I'm having is every time the job completes it appears my Tranwrd statement has only been applied on one variable. For example;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table_Y&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;first_name location&amp;nbsp;&amp;nbsp;&amp;nbsp; junk&lt;/P&gt;&lt;P&gt;&amp;nbsp;Rober$t&amp;nbsp; &amp;nbsp;LYeeXds&amp;nbsp;&amp;nbsp; &amp;nbsp;A£BCD&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;Chris£top&amp;nbsp;MYXchester&amp;nbsp;A$$BCD&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;Marti$n&amp;nbsp; &amp;nbsp;YYoXrk&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;ABC£D&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(The Tranwrd statement has been succesfully ran on the location variable).&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I change the code which creates table Y from using a set statment to using a proc append it looks like the results of my tranwrd function are&amp;nbsp;applied to each variable independently but I just can't manage to get the output into a single dataset.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;All help very much appreciated&lt;/P&gt;</description>
    <pubDate>Tue, 17 May 2016 11:13:26 GMT</pubDate>
    <dc:creator>mlcross</dc:creator>
    <dc:date>2016-05-17T11:13:26Z</dc:date>
    <item>
      <title>Tranwrd on multiple variables within a loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Tranwrd-on-multiple-variables-within-a-loop/m-p/270930#M53884</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the following code in SAS D.I studio.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My objective is to run multiple tranwrd statements (only 2 shown out of ~50) against a number of variables within a dataset. (Please note the Tranwrd 'replace' values have just been used for illustrative purposes).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options symbolgen mprint mlogic;


data table_x;
	input first_name :$10. location:$10. junk:$10.;
	datalines;
	Rober$t L$ee£ds A£BCD
	Chris£topher M$£chester A$$BCD
	Marti$n Y$o£rk ABC£D
;
run;


%macro bulk(column);

data staging_x;
	set table_x;
	&amp;amp;column. = tranwrd(&amp;amp;column.,'$','Y');
	&amp;amp;column. = tranwrd(&amp;amp;column.,'£','X');
run;

proc sql;
create table table_y as select *
	from &amp;amp;syslast.;
quit;

%mend bulk;


%macro run_now;

proc contents
	data = work.table_x;
	out = work.table_output;
quit;

proc sql noprint;
	select distinct NAME into %nrstr(:name1-:name999) from work.table_output;
quit;

data _null_;
	%do i=1 %to &amp;amp;sqlobs.;
	%let Var = &amp;amp;&amp;amp;name&amp;amp;i;
	%put Var = &amp;amp;Var.;

	%bulk(&amp;amp;Var.);

	%end
	
run;
;
%mend run_now;

%run_now;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The issue I'm having is every time the job completes it appears my Tranwrd statement has only been applied on one variable. For example;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table_Y&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;first_name location&amp;nbsp;&amp;nbsp;&amp;nbsp; junk&lt;/P&gt;&lt;P&gt;&amp;nbsp;Rober$t&amp;nbsp; &amp;nbsp;LYeeXds&amp;nbsp;&amp;nbsp; &amp;nbsp;A£BCD&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;Chris£top&amp;nbsp;MYXchester&amp;nbsp;A$$BCD&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;Marti$n&amp;nbsp; &amp;nbsp;YYoXrk&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;ABC£D&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(The Tranwrd statement has been succesfully ran on the location variable).&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I change the code which creates table Y from using a set statment to using a proc append it looks like the results of my tranwrd function are&amp;nbsp;applied to each variable independently but I just can't manage to get the output into a single dataset.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;All help very much appreciated&lt;/P&gt;</description>
      <pubDate>Tue, 17 May 2016 11:13:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Tranwrd-on-multiple-variables-within-a-loop/m-p/270930#M53884</guid>
      <dc:creator>mlcross</dc:creator>
      <dc:date>2016-05-17T11:13:26Z</dc:date>
    </item>
    <item>
      <title>Re: Tranwrd on multiple variables within a loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Tranwrd-on-multiple-variables-within-a-loop/m-p/270936#M53885</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to do the same operation on a number of varibales, I would use an array. See sample below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data table_x;
	input first_name :$10. location:$10. junk:$10.;
	datalines;
	Rober$t L$ee£ds A£BCD
	Chris£topher M$£chester A$$BCD
	Marti$n Y$o£rk ABC£D
;
run;


data staging_x;
	set table_x;
  array _trancols{*} first_name location junk;
  do _i = 1 to dim(_trancols);
	_trancols{_i} = tranwrd(_trancols{_i},'$','Y');
	_trancols{_i} = tranwrd(_trancols{_i},'£','X');
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bruno&lt;/P&gt;</description>
      <pubDate>Tue, 17 May 2016 11:28:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Tranwrd-on-multiple-variables-within-a-loop/m-p/270936#M53885</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2016-05-17T11:28:02Z</dc:date>
    </item>
    <item>
      <title>Re: Tranwrd on multiple variables within a loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Tranwrd-on-multiple-variables-within-a-loop/m-p/270937#M53886</link>
      <description>&lt;P&gt;Everytime the macro bulk is called, it will overwrite the previous staging_x and table_y with data from the original table_x, so only the last run will take effect.&lt;/P&gt;</description>
      <pubDate>Tue, 17 May 2016 11:28:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Tranwrd-on-multiple-variables-within-a-loop/m-p/270937#M53886</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-05-17T11:28:25Z</dc:date>
    </item>
    <item>
      <title>Re: Tranwrd on multiple variables within a loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Tranwrd-on-multiple-variables-within-a-loop/m-p/270963#M53891</link>
      <description>&lt;P&gt;Thanks so much for this, works a dream!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just in case anyone has similar need here is my final code;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data table_x;
	input first_name :$10. location:$10. junk:$10.;
	datalines;
	Rober$t L$ee£ds A£BCD
	Chris£topher M$£chester A$$BCD
	Marti$n Y$o£rk ABC£D
;
run;


proc contents
	data = work.table_x
	out = work.table_output;
quit;

proc sql noprint;
	select distinct NAME into :varlist separated by " " from work.table_output;  
quit;


data staging_x;
set table_x;
  array _trancols{*} &amp;amp;varlist.;
  do _i = 1 to dim(_trancols);
	_trancols{_i} = tranwrd(_trancols{_i},'$','Y');
	_trancols{_i} = tranwrd(_trancols{_i},'£','X');
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I re-inserted the proc contents statement&amp;nbsp;and created a parameter named varlist as some of the datasets I will eventually be running this code against will have a large number of variables.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Thanks again&lt;/P&gt;</description>
      <pubDate>Tue, 17 May 2016 12:53:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Tranwrd-on-multiple-variables-within-a-loop/m-p/270963#M53891</guid>
      <dc:creator>mlcross</dc:creator>
      <dc:date>2016-05-17T12:53:04Z</dc:date>
    </item>
    <item>
      <title>Re: Tranwrd on multiple variables within a loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Tranwrd-on-multiple-variables-within-a-loop/m-p/271194#M53957</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Glad it is working for you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to have all character variables be part of the array you can use the following statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array _trancols{*} _character_;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Please note, an array can only have variables of the same type.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bruno&lt;/P&gt;</description>
      <pubDate>Wed, 18 May 2016 06:31:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Tranwrd-on-multiple-variables-within-a-loop/m-p/271194#M53957</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2016-05-18T06:31:56Z</dc:date>
    </item>
  </channel>
</rss>

