<?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: Recode values of a character variable to make it sas friendly for proc transpose in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Recode-values-of-a-character-variable-to-make-it-sas-friendly/m-p/539523#M7072</link>
    <description>It's certainly possible to add a variable.  Would that do the trick?  Just before the output statement:&lt;BR /&gt;&lt;BR /&gt;V + 1;&lt;BR /&gt;fake_key = cats("val", put(v, z3.));&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Thu, 28 Feb 2019 23:47:46 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2019-02-28T23:47:46Z</dc:date>
    <item>
      <title>Recode values of a character variable to make it sas friendly for proc transpose</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Recode-values-of-a-character-variable-to-make-it-sas-friendly/m-p/539517#M7070</link>
      <description>&lt;P&gt;I have a dataset with a character variable taking around 300 unique values. Its length is 100 and some of the values are really long and have symbols inside too.&lt;/P&gt;&lt;P&gt;I need to use this variable as an id in a proc transpose, but since the values are not following sas column naming conventions I was thinking I could recode them in bulk and keep track of what code I gave to what value.&lt;/P&gt;&lt;P&gt;Only problem is I have no idea how to approach this.&lt;/P&gt;&lt;P&gt;The below code simulates my issue (test dataset - it is exaggerated though, my dataset has intelligible values followed by some codes, but you get the picture)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test1;
	length byvar $2.;
	do i=1 to 3;
		do j=1 to 2;
			substr(byvar,j)=byte(int(65+26*ranuni(0)));
		end;
		output;
	end;
	keep byvar;
run;
data test2;
	length sensor $100.;
	do i=1 to 10;
		do j=1 to 35;
			substr(sensor,j)=upcase(byte(int(113+12*ranuni(0))));
		end;
		output;
	end;
	keep sensor;
run;
proc sql noprint;
	create table test as
	select * from test1, test2;
quit;
data test;
	set test;
	length sensor_value $5.;
	do k=1 to 3;
		dt=datetime()-rannorm(0);
		l=k+floor(rannorm(0));
		t=intnx('SECOND',dt,l,'B');
		if substr(sensor,1,1)='D' then sensor_value=byte(int(65+26*ranuni(0)))||byte(int(65+26*ranuni(0)))||byte(int(65+26*ranuni(0)))||byte(int(65+26*ranuni(0)));
		else sensor_value=put(int((676+261*ranuni(0))),$5.);
		output;
	end;
	format t datetime16.;
	keep byvar sensor t sensor_value;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The troublesome variable is&amp;nbsp;&lt;STRONG&gt;sensor&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;Is there a way to replace in bulk all its unique values with say VAL1-VAL300?&lt;/P&gt;&lt;P&gt;Any other suggestions / approaches are welcome.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Feb 2019 23:28:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Recode-values-of-a-character-variable-to-make-it-sas-friendly/m-p/539517#M7070</guid>
      <dc:creator>Elle</dc:creator>
      <dc:date>2019-02-28T23:28:54Z</dc:date>
    </item>
    <item>
      <title>Re: Recode values of a character variable to make it sas friendly for proc transpose</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Recode-values-of-a-character-variable-to-make-it-sas-friendly/m-p/539522#M7071</link>
      <description>&lt;P&gt;Here is an example of one approach. You should have the data set SASHELP.CLASS available.&lt;/P&gt;
&lt;P&gt;This selects unique values of a variable, creates a recode value for each one and then merges the recoded value to the original data set into a new set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sql;
   create table list as
   select distinct name
   from sashelp.class
   order by name
   ;
quit;

data temp;
   set list;
   length recode $ 10;
   recode = catt('var',_n_);
run;

proc sql;
   create table recoded as
   select a.*, b.recode
   from sashelp.class as a
        left join
        temp as b
        on a.name=b.name
   ;
quit;

&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Feb 2019 23:45:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Recode-values-of-a-character-variable-to-make-it-sas-friendly/m-p/539522#M7071</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-02-28T23:45:25Z</dc:date>
    </item>
    <item>
      <title>Re: Recode values of a character variable to make it sas friendly for proc transpose</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Recode-values-of-a-character-variable-to-make-it-sas-friendly/m-p/539523#M7072</link>
      <description>It's certainly possible to add a variable.  Would that do the trick?  Just before the output statement:&lt;BR /&gt;&lt;BR /&gt;V + 1;&lt;BR /&gt;fake_key = cats("val", put(v, z3.));&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 28 Feb 2019 23:47:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Recode-values-of-a-character-variable-to-make-it-sas-friendly/m-p/539523#M7072</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-02-28T23:47:46Z</dc:date>
    </item>
    <item>
      <title>Re: Recode values of a character variable to make it sas friendly for proc transpose</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Recode-values-of-a-character-variable-to-make-it-sas-friendly/m-p/539564#M7080</link>
      <description>&lt;P&gt;Thank you for the code. It is working.&amp;nbsp; Why I didn't think of this is beyond me.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Mar 2019 09:16:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Recode-values-of-a-character-variable-to-make-it-sas-friendly/m-p/539564#M7080</guid>
      <dc:creator>Elle</dc:creator>
      <dc:date>2019-03-01T09:16:13Z</dc:date>
    </item>
    <item>
      <title>Re: Recode values of a character variable to make it sas friendly for proc transpose</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Recode-values-of-a-character-variable-to-make-it-sas-friendly/m-p/539565#M7081</link>
      <description>&lt;P&gt;I am not sure I follow.&lt;/P&gt;&lt;P&gt;The code I provided will generate a data similar to what I have. In my system this data already exists (the test data). The question is how can I take the variable sensor from the test dataset to recode it in bulk?&lt;/P&gt;</description>
      <pubDate>Fri, 01 Mar 2019 09:18:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Recode-values-of-a-character-variable-to-make-it-sas-friendly/m-p/539565#M7081</guid>
      <dc:creator>Elle</dc:creator>
      <dc:date>2019-03-01T09:18:45Z</dc:date>
    </item>
  </channel>
</rss>

