<?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 how to change the length of the variable for multiple datasets? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-change-the-length-of-the-variable-for-multiple-datasets/m-p/529368#M144621</link>
    <description>&lt;P&gt;Appericiate if someone of you guide me with the program to change the length of the variable for multiple datasets from one library?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assume the variable name is ID (numeric) and it has different lengths and this variable is located in multiple datasets and those datasets are in one library. Now I want to change the length of ID variable to 8 in all the datasets from all those libraries in one shot.&lt;/P&gt;</description>
    <pubDate>Wed, 23 Jan 2019 11:06:03 GMT</pubDate>
    <dc:creator>Babloo</dc:creator>
    <dc:date>2019-01-23T11:06:03Z</dc:date>
    <item>
      <title>how to change the length of the variable for multiple datasets?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-change-the-length-of-the-variable-for-multiple-datasets/m-p/529368#M144621</link>
      <description>&lt;P&gt;Appericiate if someone of you guide me with the program to change the length of the variable for multiple datasets from one library?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assume the variable name is ID (numeric) and it has different lengths and this variable is located in multiple datasets and those datasets are in one library. Now I want to change the length of ID variable to 8 in all the datasets from all those libraries in one shot.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jan 2019 11:06:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-change-the-length-of-the-variable-for-multiple-datasets/m-p/529368#M144621</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2019-01-23T11:06:03Z</dc:date>
    </item>
    <item>
      <title>Re: how to change the length of the variable for multiple datasets?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-change-the-length-of-the-variable-for-multiple-datasets/m-p/529370#M144623</link>
      <description>&lt;P&gt;You would have to recreate every relevant data set. Once a variable length is set, it can not be changed.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How do you know which data sets you want to perform this action for?&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jan 2019 11:38:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-change-the-length-of-the-variable-for-multiple-datasets/m-p/529370#M144623</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-01-23T11:38:50Z</dc:date>
    </item>
    <item>
      <title>Re: how to change the length of the variable for multiple datasets?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-change-the-length-of-the-variable-for-multiple-datasets/m-p/529371#M144624</link>
      <description>&lt;P&gt;ID variables should not be kept as numbers, but as character.&lt;/P&gt;
&lt;P&gt;Anyway, you find the datasets by searching for the variable name in sashelp.vcolumn, and create the code from that with call execute().&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jan 2019 11:39:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-change-the-length-of-the-variable-for-multiple-datasets/m-p/529371#M144624</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-01-23T11:39:15Z</dc:date>
    </item>
    <item>
      <title>Re: how to change the length of the variable for multiple datasets?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-change-the-length-of-the-variable-for-multiple-datasets/m-p/529422#M144650</link>
      <description>&lt;P&gt;1. Figure out how to do it for one data set&lt;/P&gt;
&lt;P&gt;2. Find the list of all data sets you need to do this to (been answered in previous questions)&lt;/P&gt;
&lt;P&gt;3. Use CALL EXECUTE to run it for every data set needed.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example of turning this into a macro is here:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md" target="_blank"&gt;https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you need further help post your code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/8409"&gt;@Babloo&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Appericiate if someone of you guide me with the program to change the length of the variable for multiple datasets from one library?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assume the variable name is ID (numeric) and it has different lengths and this variable is located in multiple datasets and those datasets are in one library. Now I want to change the length of ID variable to 8 in all the datasets from all those libraries in one shot.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jan 2019 15:45:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-change-the-length-of-the-variable-for-multiple-datasets/m-p/529422#M144650</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-01-23T15:45:15Z</dc:date>
    </item>
    <item>
      <title>Re: how to change the length of the variable for multiple datasets?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-change-the-length-of-the-variable-for-multiple-datasets/m-p/529468#M144672</link>
      <description>&lt;P&gt;Hi Babloo&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I Think the following macro does the trick. It changes datasets overwriting the original datasets. Write me back if you have any questions.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%macro changelength(folder);
	* Assign folder as TMP-library;
	libname tmp "&amp;amp;folder";

	* Get content of TMP-library;
	proc contents data=tmp._all_ out=w noprint;
	run;

	* Get member names - only members where variable ID exists as numeric with length not 8;
	proc sql noprint; 
		select distinct memname into :memlist  separated by ' ' from w 
		where lowcase(name) = 'id' and type = 1 and length ne 8;
	quit;

	* Copy to same member, Length statement PRECEDES Set statement to change length;
	%do i = 1 %to &amp;amp;sqlobs;
		%let mem = %scan(&amp;amp;memlist,&amp;amp;i,%str( ));
		data tmp.&amp;amp;mem; length id 8; set tmp.&amp;amp;mem; 
		run;
	%end;

	libname tmp clear;
%mend;
%changelength(c:\tmp);
%changelength(c:\etc);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 23 Jan 2019 17:56:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-change-the-length-of-the-variable-for-multiple-datasets/m-p/529468#M144672</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2019-01-23T17:56:53Z</dc:date>
    </item>
  </channel>
</rss>

