<?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: Replace old levels by new levels and keep the variables' names and type in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Replace-old-levels-by-new-levels-and-keep-the-variables-names/m-p/665687#M199084</link>
    <description>&lt;P&gt;If you mean to update in place then you may have at least one issue that won't allow that: the lengths of the variables involved. If your current value has a length of one, all that would be needed to hold a, b, c etc and try to fit in a value of 1st, 2nd or 3rd then you need to have a length of at least 3.&lt;/P&gt;
&lt;P&gt;So before even starting you need to check the lengths of 1000 variables to make sure that the longest value of your "new level" would fit.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your second data set is almost usable to create a custom format with Varname as a format name, levels as the Start and New_level as the label value. Look at Proc format and CNTLIN option. Then you could use the format with the existing "level" to display the text of the new level.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But there are some details about "blank" values that may need to be clarified as well such as do any of the variables with "blank" have the blank associated with two, or possibly more, new level values?&lt;/P&gt;</description>
    <pubDate>Mon, 29 Jun 2020 02:37:36 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2020-06-29T02:37:36Z</dc:date>
    <item>
      <title>Replace old levels by new levels and keep the variables' names and type</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-old-levels-by-new-levels-and-keep-the-variables-names/m-p/665685#M199082</link>
      <description>&lt;P&gt;I have 2 datasets which look like below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;First:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;var1&amp;nbsp; var2&amp;nbsp; ...&amp;nbsp; var1000&amp;nbsp; &amp;nbsp; &amp;nbsp;Y&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;n&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;f&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1111&lt;/P&gt;
&lt;P&gt;&amp;nbsp; c&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;n&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;f&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;111&lt;/P&gt;
&lt;P&gt;&amp;nbsp; d&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;o&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; g&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;222&lt;/P&gt;
&lt;P&gt;&amp;nbsp; b&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;o&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; g&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4444&lt;/P&gt;
&lt;P&gt;&amp;nbsp; b&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;h&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;7777&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;p&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; g&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;222&lt;/P&gt;
&lt;P&gt;&amp;nbsp; c&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;q&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; g&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4444&lt;/P&gt;
&lt;P&gt;&amp;nbsp; d&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; r&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; h&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;77&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Second:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;varName&amp;nbsp; &amp;nbsp;Levels&amp;nbsp; &amp;nbsp; &amp;nbsp; new_level&lt;/P&gt;
&lt;P&gt;&amp;nbsp; var1&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; 2nd&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; var1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;b&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3rd&lt;/P&gt;
&lt;P&gt;&amp;nbsp; var1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;c&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1st&lt;/P&gt;
&lt;P&gt;&amp;nbsp; var1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;d&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3rd&lt;/P&gt;
&lt;P&gt;&amp;nbsp; var2&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; 3rd&lt;/P&gt;
&lt;P&gt;&amp;nbsp; var2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;n&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4th&lt;/P&gt;
&lt;P&gt;&amp;nbsp; var2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;o&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2nd&lt;/P&gt;
&lt;P&gt;&amp;nbsp; var2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;p&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 4th&lt;/P&gt;
&lt;P&gt;&amp;nbsp; var2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;q&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2nd&lt;/P&gt;
&lt;P&gt;&amp;nbsp; var2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;r&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1st&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;var1000&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;f&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2nd&lt;/P&gt;
&lt;P&gt;&amp;nbsp;var1000&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;g&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2nd&lt;/P&gt;
&lt;P&gt;&amp;nbsp;var1000&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;h&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1st&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want the first dataset to have new levels from the second dataset with the same name and type of the variables in the first dataset like below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;want:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;var1&amp;nbsp; var2&amp;nbsp; ...&amp;nbsp; var1000&amp;nbsp; &amp;nbsp; &amp;nbsp; Y&lt;/P&gt;
&lt;P&gt;2nd&amp;nbsp; &amp;nbsp; &amp;nbsp;4th&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2nd&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1111&lt;/P&gt;
&lt;P&gt;1st&amp;nbsp; &amp;nbsp; &amp;nbsp; 4th&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2nd&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;111&lt;/P&gt;
&lt;P&gt;3rd&amp;nbsp; &amp;nbsp; &amp;nbsp; 2nd&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2nd&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;222&lt;/P&gt;
&lt;P&gt;3rd&amp;nbsp; &amp;nbsp; &amp;nbsp; 2nd&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2nd&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4444&lt;/P&gt;
&lt;P&gt;3rd&amp;nbsp; &amp;nbsp; &amp;nbsp; 3rd&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2nd&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;7777&lt;/P&gt;
&lt;P&gt;2nd&amp;nbsp; &amp;nbsp; &amp;nbsp;4th&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2nd&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;222&lt;/P&gt;
&lt;P&gt;1st&amp;nbsp; &amp;nbsp; &amp;nbsp; 2nd&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2nd&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4444&lt;/P&gt;
&lt;P&gt;3rd&amp;nbsp; &amp;nbsp; &amp;nbsp; 1st&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1st&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 77&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your help would be greatly appreciated!&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jun 2020 02:07:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-old-levels-by-new-levels-and-keep-the-variables-names/m-p/665685#M199082</guid>
      <dc:creator>mh2t</dc:creator>
      <dc:date>2020-06-29T02:07:26Z</dc:date>
    </item>
    <item>
      <title>Re: Replace old levels by new levels and keep the variables' names and type</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-old-levels-by-new-levels-and-keep-the-variables-names/m-p/665687#M199084</link>
      <description>&lt;P&gt;If you mean to update in place then you may have at least one issue that won't allow that: the lengths of the variables involved. If your current value has a length of one, all that would be needed to hold a, b, c etc and try to fit in a value of 1st, 2nd or 3rd then you need to have a length of at least 3.&lt;/P&gt;
&lt;P&gt;So before even starting you need to check the lengths of 1000 variables to make sure that the longest value of your "new level" would fit.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your second data set is almost usable to create a custom format with Varname as a format name, levels as the Start and New_level as the label value. Look at Proc format and CNTLIN option. Then you could use the format with the existing "level" to display the text of the new level.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But there are some details about "blank" values that may need to be clarified as well such as do any of the variables with "blank" have the blank associated with two, or possibly more, new level values?&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jun 2020 02:37:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-old-levels-by-new-levels-and-keep-the-variables-names/m-p/665687#M199084</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-06-29T02:37:36Z</dc:date>
    </item>
    <item>
      <title>Re: Replace old levels by new levels and keep the variables' names and type</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-old-levels-by-new-levels-and-keep-the-variables-names/m-p/665689#M199085</link>
      <description>&lt;P&gt;One Way :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data first;
input var1 $ var2  $ var1000   $   Y;
cards;
a b c 111
c n f 111
d x g 222
;
run;

data second;
input varName $  Levels   $   new_level $;
cards;
var1 a 2nd
var1 c 1st
var1 d 3rd
var2 b 1st
var2 n 3rd
var2 o 2nd
var1000 g 5th
;
run;

data want;
	if _n_=1 then do;

		if 0 then
			set second;
		declare hash h(dataset:'second');
		h.definekey('varName','Levels');
		h.definedata('new_level');
		h.definedone();
	end;
	set first;
	array v[*] var1 var2 var1000;
	

	do i=1 to dim(v);
	 if h.find(key:vname(v[i]),key:v[i]) eq 0 then v[i]=new_level;
	 	else call missing(of v[i]);
	end;
	
	drop i varName Levels new_level;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 29 Jun 2020 03:10:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-old-levels-by-new-levels-and-keep-the-variables-names/m-p/665689#M199085</guid>
      <dc:creator>r_behata</dc:creator>
      <dc:date>2020-06-29T03:10:33Z</dc:date>
    </item>
    <item>
      <title>Re: Replace old levels by new levels and keep the variables' names and type</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-old-levels-by-new-levels-and-keep-the-variables-names/m-p/665755#M199111</link>
      <description>&lt;P&gt;As Reeza said, proc format also is a proper tool.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data first;
input var1 $ var2  $ var1000   $   Y;
cards;
a b c 111
c n f 111
d x g 222
;
run;

data second;
input varName $  Levels   $   new_level $;
cards;
var1 a 2nd
var1 c 1st
var1 d 3rd
var2 b 1st
var2 n 3rd
var2 o 2nd
var1000 g 5th
;
run;

data fmt;
 set second;
 type='C';
 varName=cats(varName,'_');
 rename varName=fmtname Levels=start new_level=label;
run;
proc format cntlin=fmt;
run;

data want;
 set first;
 array x{*} $ var1--var1000;
 array _x{3} $40 _var1 _var2 _var1000;
 do i=1 to dim(x);
  _x{i}=putc(x{i},cats(vname(x{i}),'_'));
 end;
 drop i;
run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 29 Jun 2020 11:29:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-old-levels-by-new-levels-and-keep-the-variables-names/m-p/665755#M199111</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-06-29T11:29:57Z</dc:date>
    </item>
  </channel>
</rss>

