<?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: Dynamically change the variable attributes in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-change-the-variable-attributes/m-p/255601#M48839</link>
    <description>Or how about just do &lt;BR /&gt;length var1-var2 $10;</description>
    <pubDate>Wed, 09 Mar 2016 18:13:15 GMT</pubDate>
    <dc:creator>data_null__</dc:creator>
    <dc:date>2016-03-09T18:13:15Z</dc:date>
    <item>
      <title>Dynamically change the variable attributes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-change-the-variable-attributes/m-p/255599#M48837</link>
      <description>&lt;P&gt;This macro code creates the code below. I want to create only one length statement and only variable names changing dynamically.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data test;
input var1 $ var2 $;
cards;
 1 4
 2 5
 3 6
 ;

%macro m;

	data test;
		%do i= 1 %to 2;
			length var&amp;amp;i $ 10.;
		%end;

		set test;
	run;

%mend m;

%m

/* cod generated */

data test;
	length var1 $ 10.;
	length var2 $ 10.;
	set test;
run;

/* desired code */

data test;
	length var1 $ 10.
           var2 $ 10.;
	set test;
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 09 Mar 2016 18:00:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-change-the-variable-attributes/m-p/255599#M48837</guid>
      <dc:creator>SAS_inquisitive</dc:creator>
      <dc:date>2016-03-09T18:00:36Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically change the variable attributes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-change-the-variable-attributes/m-p/255600#M48838</link>
      <description>Just move the word LENGTH before %DO and semi-colon after %end;</description>
      <pubDate>Wed, 09 Mar 2016 18:12:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-change-the-variable-attributes/m-p/255600#M48838</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2016-03-09T18:12:04Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically change the variable attributes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-change-the-variable-attributes/m-p/255601#M48839</link>
      <description>Or how about just do &lt;BR /&gt;length var1-var2 $10;</description>
      <pubDate>Wed, 09 Mar 2016 18:13:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-change-the-variable-attributes/m-p/255601#M48839</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2016-03-09T18:13:15Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically change the variable attributes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-change-the-variable-attributes/m-p/255602#M48840</link>
      <description>&lt;P&gt;Definitely a worthwhile technique to learn!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's what you have now:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%do i=1 %to 2;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; length var&amp;amp;i $ 10.;&lt;/P&gt;
&lt;P&gt;%end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's what the replacement would look like (notice the dot is not required when defining length, only for formats):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;length&lt;/P&gt;
&lt;P&gt;%do i=1 %to 2;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; var&amp;amp;i&lt;/P&gt;
&lt;P&gt;%end;&lt;/P&gt;
&lt;P&gt;$ 10;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good luck.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Mar 2016 18:13:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-change-the-variable-attributes/m-p/255602#M48840</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-03-09T18:13:41Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically change the variable attributes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-change-the-variable-attributes/m-p/255606#M48842</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15410"&gt;@data_null__﻿&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding﻿&lt;/a&gt;. &amp;nbsp;Thank you. May be I could start another thread. What if &amp;nbsp;variables are not var1 and var2 (ie. can not referenced by macro variable &amp;amp;i) such as x and y and I need to change &amp;nbsp;their attributes inside macro definition.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input x $ y $;
cards;
 1 4
 2 5
 3 6
 ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Mar 2016 18:29:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-change-the-variable-attributes/m-p/255606#M48842</guid>
      <dc:creator>SAS_inquisitive</dc:creator>
      <dc:date>2016-03-09T18:29:29Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically change the variable attributes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-change-the-variable-attributes/m-p/255609#M48844</link>
      <description>&lt;P&gt;The answer depends on how the variable names are stored.&amp;nbsp; For example, do you have a macro variable holding a list of variable names:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let var_list = x var1 y;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you have a data set where a DATA step variable takes on values of "x" "var1" and "y"?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How do you expect to provide the list of variable names?&lt;/P&gt;</description>
      <pubDate>Wed, 09 Mar 2016 18:35:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-change-the-variable-attributes/m-p/255609#M48844</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-03-09T18:35:04Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically change the variable attributes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-change-the-variable-attributes/m-p/255627#M48853</link>
      <description>@ Astounding. Yes, the horizontal list as you mentioned.&lt;BR /&gt;%let var_list=x y;</description>
      <pubDate>Wed, 09 Mar 2016 19:37:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-change-the-variable-attributes/m-p/255627#M48853</guid>
      <dc:creator>SAS_inquisitive</dc:creator>
      <dc:date>2016-03-09T19:37:02Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically change the variable attributes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-change-the-variable-attributes/m-p/255630#M48854</link>
      <description>&lt;P&gt;When you already have all the variable names assembled in a single macro variable, I would skip the looping:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;length &amp;amp;var_list $ 10;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Mar 2016 19:52:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-change-the-variable-attributes/m-p/255630#M48854</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-03-09T19:52:04Z</dc:date>
    </item>
  </channel>
</rss>

