<?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 more effecient codes for repetitive data steps in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/more-effecient-codes-for-repetitive-data-steps/m-p/443242#M282839</link>
    <description>&lt;P&gt;if index_year=1990 then &amp;amp;name.0=&amp;amp;name.1990;&lt;/P&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am a relatively new SAS user and currently working with longitudinal data. In order to shape my&amp;nbsp;data I am running a number&amp;nbsp;of repetitive commands daily. For example, I need to assign time point depending on the index year. If index&amp;nbsp;year is 1990, then timepoint starts from 1990. I have many variables and 28 time points and this makes my codes are just so bulky. Do you have any suggestions how I can apply macros or loops to save space and writing time? Thank you.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let name=_alcdep;&lt;BR /&gt;DATA db;&lt;BR /&gt;set db;&lt;/P&gt;&lt;P&gt;if index_year=1990 then &amp;amp;name.1=&amp;amp;name.1991;&lt;BR /&gt;if index_year=1990 then &amp;amp;name.2=&amp;amp;name.1992;&lt;BR /&gt;if index_year=1990 then &amp;amp;name.3=&amp;amp;name.1993;&lt;BR /&gt;if index_year=1990 then &amp;amp;name.4=&amp;amp;name.1994;&lt;BR /&gt;if index_year=1990 then &amp;amp;name.5=&amp;amp;name.1995;&lt;BR /&gt;...&lt;BR /&gt;if index_year=1991 then &amp;amp;name.0=&amp;amp;name.1991;&lt;BR /&gt;if index_year=1991 then &amp;amp;name.1=&amp;amp;name.1992;&lt;BR /&gt;if index_year=1991 then &amp;amp;name.2=&amp;amp;name.1993;&lt;BR /&gt;if index_year=1991 then &amp;amp;name.3=&amp;amp;name.1994;&lt;BR /&gt;if index_year=1991 then &amp;amp;name.4=&amp;amp;name.1995;&lt;BR /&gt;....&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;</description>
    <pubDate>Wed, 07 Mar 2018 11:39:33 GMT</pubDate>
    <dc:creator>msxas90</dc:creator>
    <dc:date>2018-03-07T11:39:33Z</dc:date>
    <item>
      <title>more effecient codes for repetitive data steps</title>
      <link>https://communities.sas.com/t5/SAS-Programming/more-effecient-codes-for-repetitive-data-steps/m-p/443242#M282839</link>
      <description>&lt;P&gt;if index_year=1990 then &amp;amp;name.0=&amp;amp;name.1990;&lt;/P&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am a relatively new SAS user and currently working with longitudinal data. In order to shape my&amp;nbsp;data I am running a number&amp;nbsp;of repetitive commands daily. For example, I need to assign time point depending on the index year. If index&amp;nbsp;year is 1990, then timepoint starts from 1990. I have many variables and 28 time points and this makes my codes are just so bulky. Do you have any suggestions how I can apply macros or loops to save space and writing time? Thank you.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let name=_alcdep;&lt;BR /&gt;DATA db;&lt;BR /&gt;set db;&lt;/P&gt;&lt;P&gt;if index_year=1990 then &amp;amp;name.1=&amp;amp;name.1991;&lt;BR /&gt;if index_year=1990 then &amp;amp;name.2=&amp;amp;name.1992;&lt;BR /&gt;if index_year=1990 then &amp;amp;name.3=&amp;amp;name.1993;&lt;BR /&gt;if index_year=1990 then &amp;amp;name.4=&amp;amp;name.1994;&lt;BR /&gt;if index_year=1990 then &amp;amp;name.5=&amp;amp;name.1995;&lt;BR /&gt;...&lt;BR /&gt;if index_year=1991 then &amp;amp;name.0=&amp;amp;name.1991;&lt;BR /&gt;if index_year=1991 then &amp;amp;name.1=&amp;amp;name.1992;&lt;BR /&gt;if index_year=1991 then &amp;amp;name.2=&amp;amp;name.1993;&lt;BR /&gt;if index_year=1991 then &amp;amp;name.3=&amp;amp;name.1994;&lt;BR /&gt;if index_year=1991 then &amp;amp;name.4=&amp;amp;name.1995;&lt;BR /&gt;....&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Mar 2018 11:39:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/more-effecient-codes-for-repetitive-data-steps/m-p/443242#M282839</guid>
      <dc:creator>msxas90</dc:creator>
      <dc:date>2018-03-07T11:39:33Z</dc:date>
    </item>
    <item>
      <title>Re: more effecient codes for repetitive data steps</title>
      <link>https://communities.sas.com/t5/SAS-Programming/more-effecient-codes-for-repetitive-data-steps/m-p/443252#M282840</link>
      <description>&lt;P&gt;Making long tables will end you up in awkward programming situations, so avoid it whenever possible.&lt;/P&gt;
&lt;P&gt;But for your case, wrap your code into a macro, and use a %do loop to assign the year to your variables dynamically.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Mar 2018 11:57:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/more-effecient-codes-for-repetitive-data-steps/m-p/443252#M282840</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2018-03-07T11:57:34Z</dc:date>
    </item>
    <item>
      <title>Re: more effecient codes for repetitive data steps</title>
      <link>https://communities.sas.com/t5/SAS-Programming/more-effecient-codes-for-repetitive-data-steps/m-p/443255#M282841</link>
      <description>&lt;P&gt;Using arrays?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array names {0:5} &amp;amp;name.0-&amp;amp;name.5;
array oldnames {0:5} &amp;amp;name.1990-&amp;amp;name.1995;
if index_year=1990 then do i = 1 to 5;
  names{i} = oldnames{i};
end;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and I guess you could expand that logic even for your index_year values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: deleted a mis-typed character;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Mar 2018 12:07:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/more-effecient-codes-for-repetitive-data-steps/m-p/443255#M282841</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-03-07T12:07:50Z</dc:date>
    </item>
    <item>
      <title>Re: more effecient codes for repetitive data steps</title>
      <link>https://communities.sas.com/t5/SAS-Programming/more-effecient-codes-for-repetitive-data-steps/m-p/443269#M282842</link>
      <description>&lt;P&gt;Thank you so much! this is exactly what I was looking for.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Mar 2018 12:45:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/more-effecient-codes-for-repetitive-data-steps/m-p/443269#M282842</guid>
      <dc:creator>msxas90</dc:creator>
      <dc:date>2018-03-07T12:45:55Z</dc:date>
    </item>
  </channel>
</rss>

