<?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 converting an array into a looping macro program in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/converting-an-array-into-a-looping-macro-program/m-p/692976#M211221</link>
    <description>&lt;DIV class="Page-container"&gt;&lt;DIV class="Page PageComponent"&gt;&lt;DIV class="Draw Draw--not-drawing Draw--selection"&gt;&lt;DIV class="TextLayer-container"&gt;&lt;DIV class="textLayer"&gt;&lt;SPAN class="textLayer--absolute"&gt;Hello,&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="textLayer"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="textLayer"&gt;&lt;SPAN class="textLayer--absolute"&gt;I'm new to macros and arrays. This was an assignment I had from a few weeks ago that I don't think I did correctly.&amp;nbsp; Part three looping macros is what is giving me trouble. Can someone tell me where I am going wrong? I'm attaching the assignment and my code. I think what gets me confused is when my professor tells me to convert my array into a macro. Am I converting an array into a macro? Also, The single macro with parameters runs fine, but my final macro is a mess. What am I doing wrong?&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="textLayer"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="textLayer"&gt;&lt;SPAN class="textLayer--absolute"&gt;Thank you,&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="textLayer"&gt;&lt;SPAN class="textLayer--absolute"&gt;Kim&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="textLayer"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="textLayer"&gt;&lt;SPAN class="textLayer--absolute"&gt;***Assignment***&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="textLayer"&gt;&lt;SPAN class="textLayer--absolute"&gt;Lo&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;ops, Arrays, and Ma&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;cros:&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;A Little Fun? &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;with Wordsum&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;Introduction:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="textLayer"&gt;&lt;SPAN class="textLayer--absolute"&gt;This assignment&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt; is due October 5&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;. It will conclude our tour &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;of &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;computational techniques &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;that advanced survey data an&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;alysts s&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;hould be able to empl&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;oy. The emphasis here i&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;s on concise, elegant &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;code that c&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;auses great things to happen.&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt; Submit code and logs. Grades will be based on how few lines &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;(semicolons) of code you use to accomplish the tasks.&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt; To be sure, this one starts out fairly easy and &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;becomes very challen&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;ging.&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt; You will iterate through a lot of&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt; variations in code. Start early&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;. It actually is &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;rewarding when you crack the coding nut.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="textLayer"&gt;&lt;SPAN class="textLayer--absolute"&gt;Background:&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt; Study up on the W&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;ORDSUM and W&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;ORDA&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;—WORDJ &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;variables in the GSS cumulative file. &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;You will find &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;that this is a&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt; verbal intelligence test designed for surv&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;eys. Like a lot of &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;methodological &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;innovations, Gallup started using t&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;his in the 1940s. Pay special&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;&amp;nbsp;attention to the years in which these &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;items appeared on GSS&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt; (hint: see around pg. 3761 in the codebook .pdf file). &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="textLayer"&gt;&lt;SPAN class="textLayer--absolute"&gt;You should be able to do &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;this in about 20 lines of code. The point is to let&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt; the computer do the&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt; repetition while you sit back and &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;watch.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="textLayer"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="textLayer"&gt;&lt;SPAN class="textLayer--absolute"&gt;Ta&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;sks:&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;1)&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;Arrays and Loops&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;Locate the “&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;Simplifyin&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;g Programs with Arrays&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;” section in the &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;Little S&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;AS Book&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt; which is section 3.11 in the &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;fifth edition. Using only the data for 1988, f&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;ollow the example to define an array that designates the &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;WORD&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;x variables&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;, loops across all array cells, and &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;assigns missing values.&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt; Check your results with &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;appr&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;opriate&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt; tabulations.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="textLayer"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="textLayer"&gt;&lt;SPAN class="textLayer--absolute"&gt;2)&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;Macro&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt; with Parameters&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;Using the &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;“Adding Parameters to Macros&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;” section (7.4 in the fifth ed&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;ition), &lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN class="textLayer--absolute"&gt;conve&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;rt the array&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt; de&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;veloped &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;in (1) to a macro which substitutes&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN class="textLayer--absolute"&gt;&lt;STRONG&gt; in 1988 for a generic year variable.&lt;/STRONG&gt; That is, instruct the macro to run &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;on the 1988 data. &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;Pay special at&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;tention to the macro commands that always begin with “&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;%”. &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="textLayer"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="textLayer"&gt;&lt;STRONG&gt;&lt;SPAN class="textLayer--absolute"&gt;3)&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;Macro &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;that Loops acr&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;oss Mu&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;ltiple Years&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;Once you &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;have&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt; your macro working for 1988, add &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;code that instructs the ma&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;cro to parse across all y&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;ea&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;rs &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;of available data. This is not documented in the book&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;. The basi&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;c form of the&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt; macro&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt; loop looks like this:&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV class="textLayer"&gt;&lt;STRONG&gt;&lt;SPAN class="textLayer--absolute"&gt;%macro &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;macroname&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;; &lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV class="textLayer"&gt;&lt;STRONG&gt;&lt;SPAN class="textLayer--absolute"&gt;%do &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;i = &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;start_value&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt; %to &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;end&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt; value&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt; %by &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;increment&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt; ;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV class="textLayer"&gt;&lt;STRONG&gt;&lt;SPAN class="textLayer--absolute"&gt;%&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;callmacro&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;(var&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;=&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;&amp;amp;i&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;) &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;%end;&lt;/SPAN&gt; &lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV class="textLayer"&gt;&lt;STRONG&gt;&lt;SPAN class="textLayer--absolute"&gt;%&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;mend &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;macro&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;name&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;; &lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV class="textLayer"&gt;&lt;STRONG&gt;&lt;SPAN class="textLayer--absolute"&gt;Where &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;macroname&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt; = a name you giv&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;e the macro that runs across years. &lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV class="textLayer"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="textLayer"&gt;&lt;SPAN class="textLayer--absolute"&gt;The loop start value is the first &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;value you want to &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;use&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt; for this loop &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;(e.g., 1988)&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;, end value is th&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;e last &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;value (&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;end &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;year), and increment is &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;how much the start value is incr&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;eased on each i&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;teration. It&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;’s easy for the period wh&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;en GSS&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt; data were &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;col&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;lected every year. The &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;increment is one (the de&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;fault). But, you need to figure out what to do when &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;the survey becomes &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;biennial (not exactly rocket s&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;cience, but you can do it).&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt; Look back at the co&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;de&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;book &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;page noted abo&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;ve&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt; for a reminder of what years the WORDSUM data were collected&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;. Where &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;I have &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;inserted &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;call macro&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;, you put the name of the ma&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;cro you develop&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;ed&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt; in step 2. The&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt; step&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt; 3 loop will keep&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute" style="font-family: inherit;"&gt;running th&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute" style="font-family: inherit;"&gt;at macro over and over until all years &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute" style="font-family: inherit;"&gt;have&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute" style="font-family: inherit;"&gt; been &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute" style="font-family: inherit;"&gt;parsed. &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute" style="font-family: inherit;"&gt;Hint: When I did this step I &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute" style="font-family: inherit;"&gt;embedded three do loops in the ma&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute" style="font-family: inherit;"&gt;cro d&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute" style="font-family: inherit;"&gt;ue to variations in year increment&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute" style="font-family: inherit;"&gt;s and skip patter&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute" style="font-family: inherit;"&gt;ns. Gold star&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute" style="font-family: inherit;"&gt;to someone(s) who can figure out a way to do it in fewer loops.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="textLayer"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="textLayer"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="textLayer"&gt;&lt;SPAN class="textLayer--absolute" style="font-family: inherit;"&gt;***My Code***&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="textLayer"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="textLayer"&gt;&lt;P&gt;libname in "C:\Users\kim_trevino1\Desktop\Advanced STATS 2020"; run;&lt;/P&gt;&lt;P&gt;*options symbolgen;&lt;/P&gt;&lt;P&gt;Data work.worddata2;&lt;BR /&gt;set in.gss7218_r3(Keep= Year ID marital wrkstat hrs1 age educ region sex race&lt;BR /&gt;rincome income occ10 prestg10 indus10 size worda wordB wordc wordd worde wordf wordg wordh wordi wordj wordsum wtssall);&lt;/P&gt;&lt;P&gt;Array worddata (10)$ worda --wordj; /*wordsum not included because 9 is a value and not missin*/&lt;BR /&gt;Do i= 1 to 10;&lt;BR /&gt;if worddata(i)in (9,-1)then worddata (i)=.;&lt;BR /&gt;/*Where year=1988*/&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Proc freq data=work.worddata2;&lt;BR /&gt;Table year*worda--wordsum;&lt;BR /&gt;weight wtssall;&lt;BR /&gt;Run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data work.worddatamacro;&lt;BR /&gt;set work.worddata2;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro wordscore(year);&lt;BR /&gt;proc sort data=work.worddatamacro; by year; run;&lt;/P&gt;&lt;P&gt;*read following data;&lt;BR /&gt;proc freq data=work.worddatamacro;&lt;BR /&gt;where year=&amp;amp;year.;&lt;BR /&gt;tables worda--wordsum;&lt;BR /&gt;title 'Word Score for &amp;amp;year.';&lt;BR /&gt;run;&lt;BR /&gt;%mend wordscore;&lt;/P&gt;&lt;P&gt;data worddata3; set work.worddatamacro;Run;&lt;/P&gt;&lt;P&gt;%wordscore(1988);&lt;/P&gt;&lt;P&gt;%macro wordscore (year);&lt;BR /&gt;%Do i=1974 %to 1984 %by 2; %wordscore(year=&amp;amp;i.) %end;&lt;BR /&gt;%Do i=1987 %to 1994 %by 1; %wordscore(year=&amp;amp;i.) %end;&lt;BR /&gt;%Do i=1996 %to 2000 %by 2; %wordscore(year=&amp;amp;i.) %end;&lt;BR /&gt;%Do i=2004 %to 2018 %by 2; %wordscore(year=&amp;amp;i.) %end;&lt;/P&gt;&lt;P&gt;%mend wordscore;&lt;BR /&gt;%wordscore;&lt;BR /&gt;Ods rtf close;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
    <pubDate>Tue, 20 Oct 2020 18:03:03 GMT</pubDate>
    <dc:creator>kim_trevino1</dc:creator>
    <dc:date>2020-10-20T18:03:03Z</dc:date>
    <item>
      <title>converting an array into a looping macro program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-an-array-into-a-looping-macro-program/m-p/692976#M211221</link>
      <description>&lt;DIV class="Page-container"&gt;&lt;DIV class="Page PageComponent"&gt;&lt;DIV class="Draw Draw--not-drawing Draw--selection"&gt;&lt;DIV class="TextLayer-container"&gt;&lt;DIV class="textLayer"&gt;&lt;SPAN class="textLayer--absolute"&gt;Hello,&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="textLayer"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="textLayer"&gt;&lt;SPAN class="textLayer--absolute"&gt;I'm new to macros and arrays. This was an assignment I had from a few weeks ago that I don't think I did correctly.&amp;nbsp; Part three looping macros is what is giving me trouble. Can someone tell me where I am going wrong? I'm attaching the assignment and my code. I think what gets me confused is when my professor tells me to convert my array into a macro. Am I converting an array into a macro? Also, The single macro with parameters runs fine, but my final macro is a mess. What am I doing wrong?&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="textLayer"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="textLayer"&gt;&lt;SPAN class="textLayer--absolute"&gt;Thank you,&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="textLayer"&gt;&lt;SPAN class="textLayer--absolute"&gt;Kim&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="textLayer"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="textLayer"&gt;&lt;SPAN class="textLayer--absolute"&gt;***Assignment***&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="textLayer"&gt;&lt;SPAN class="textLayer--absolute"&gt;Lo&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;ops, Arrays, and Ma&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;cros:&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;A Little Fun? &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;with Wordsum&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;Introduction:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="textLayer"&gt;&lt;SPAN class="textLayer--absolute"&gt;This assignment&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt; is due October 5&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;. It will conclude our tour &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;of &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;computational techniques &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;that advanced survey data an&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;alysts s&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;hould be able to empl&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;oy. The emphasis here i&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;s on concise, elegant &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;code that c&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;auses great things to happen.&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt; Submit code and logs. Grades will be based on how few lines &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;(semicolons) of code you use to accomplish the tasks.&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt; To be sure, this one starts out fairly easy and &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;becomes very challen&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;ging.&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt; You will iterate through a lot of&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt; variations in code. Start early&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;. It actually is &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;rewarding when you crack the coding nut.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="textLayer"&gt;&lt;SPAN class="textLayer--absolute"&gt;Background:&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt; Study up on the W&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;ORDSUM and W&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;ORDA&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;—WORDJ &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;variables in the GSS cumulative file. &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;You will find &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;that this is a&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt; verbal intelligence test designed for surv&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;eys. Like a lot of &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;methodological &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;innovations, Gallup started using t&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;his in the 1940s. Pay special&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;&amp;nbsp;attention to the years in which these &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;items appeared on GSS&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt; (hint: see around pg. 3761 in the codebook .pdf file). &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="textLayer"&gt;&lt;SPAN class="textLayer--absolute"&gt;You should be able to do &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;this in about 20 lines of code. The point is to let&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt; the computer do the&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt; repetition while you sit back and &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;watch.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="textLayer"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="textLayer"&gt;&lt;SPAN class="textLayer--absolute"&gt;Ta&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;sks:&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;1)&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;Arrays and Loops&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;Locate the “&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;Simplifyin&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;g Programs with Arrays&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;” section in the &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;Little S&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;AS Book&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt; which is section 3.11 in the &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;fifth edition. Using only the data for 1988, f&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;ollow the example to define an array that designates the &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;WORD&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;x variables&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;, loops across all array cells, and &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;assigns missing values.&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt; Check your results with &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;appr&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;opriate&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt; tabulations.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="textLayer"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="textLayer"&gt;&lt;SPAN class="textLayer--absolute"&gt;2)&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;Macro&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt; with Parameters&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;Using the &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;“Adding Parameters to Macros&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;” section (7.4 in the fifth ed&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;ition), &lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN class="textLayer--absolute"&gt;conve&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;rt the array&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt; de&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;veloped &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;in (1) to a macro which substitutes&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN class="textLayer--absolute"&gt;&lt;STRONG&gt; in 1988 for a generic year variable.&lt;/STRONG&gt; That is, instruct the macro to run &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;on the 1988 data. &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;Pay special at&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;tention to the macro commands that always begin with “&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;%”. &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="textLayer"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="textLayer"&gt;&lt;STRONG&gt;&lt;SPAN class="textLayer--absolute"&gt;3)&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;Macro &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;that Loops acr&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;oss Mu&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;ltiple Years&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;Once you &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;have&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt; your macro working for 1988, add &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;code that instructs the ma&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;cro to parse across all y&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;ea&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;rs &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;of available data. This is not documented in the book&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;. The basi&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;c form of the&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt; macro&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt; loop looks like this:&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV class="textLayer"&gt;&lt;STRONG&gt;&lt;SPAN class="textLayer--absolute"&gt;%macro &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;macroname&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;; &lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV class="textLayer"&gt;&lt;STRONG&gt;&lt;SPAN class="textLayer--absolute"&gt;%do &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;i = &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;start_value&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt; %to &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;end&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt; value&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt; %by &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;increment&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt; ;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV class="textLayer"&gt;&lt;STRONG&gt;&lt;SPAN class="textLayer--absolute"&gt;%&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;callmacro&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;(var&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;=&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;&amp;amp;i&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;) &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;%end;&lt;/SPAN&gt; &lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV class="textLayer"&gt;&lt;STRONG&gt;&lt;SPAN class="textLayer--absolute"&gt;%&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;mend &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;macro&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;name&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;; &lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV class="textLayer"&gt;&lt;STRONG&gt;&lt;SPAN class="textLayer--absolute"&gt;Where &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;macroname&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt; = a name you giv&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;e the macro that runs across years. &lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV class="textLayer"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="textLayer"&gt;&lt;SPAN class="textLayer--absolute"&gt;The loop start value is the first &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;value you want to &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;use&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt; for this loop &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;(e.g., 1988)&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;, end value is th&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;e last &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;value (&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;end &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;year), and increment is &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;how much the start value is incr&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;eased on each i&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;teration. It&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;’s easy for the period wh&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;en GSS&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt; data were &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;col&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;lected every year. The &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;increment is one (the de&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;fault). But, you need to figure out what to do when &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;the survey becomes &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;biennial (not exactly rocket s&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;cience, but you can do it).&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt; Look back at the co&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;de&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;book &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;page noted abo&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;ve&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt; for a reminder of what years the WORDSUM data were collected&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;. Where &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;I have &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;inserted &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;call macro&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;, you put the name of the ma&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;cro you develop&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt;ed&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt; in step 2. The&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt; step&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute"&gt; 3 loop will keep&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute" style="font-family: inherit;"&gt;running th&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute" style="font-family: inherit;"&gt;at macro over and over until all years &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute" style="font-family: inherit;"&gt;have&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute" style="font-family: inherit;"&gt; been &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute" style="font-family: inherit;"&gt;parsed. &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute" style="font-family: inherit;"&gt;Hint: When I did this step I &lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute" style="font-family: inherit;"&gt;embedded three do loops in the ma&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute" style="font-family: inherit;"&gt;cro d&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute" style="font-family: inherit;"&gt;ue to variations in year increment&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute" style="font-family: inherit;"&gt;s and skip patter&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute" style="font-family: inherit;"&gt;ns. Gold star&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="textLayer--absolute" style="font-family: inherit;"&gt;to someone(s) who can figure out a way to do it in fewer loops.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="textLayer"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="textLayer"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="textLayer"&gt;&lt;SPAN class="textLayer--absolute" style="font-family: inherit;"&gt;***My Code***&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="textLayer"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="textLayer"&gt;&lt;P&gt;libname in "C:\Users\kim_trevino1\Desktop\Advanced STATS 2020"; run;&lt;/P&gt;&lt;P&gt;*options symbolgen;&lt;/P&gt;&lt;P&gt;Data work.worddata2;&lt;BR /&gt;set in.gss7218_r3(Keep= Year ID marital wrkstat hrs1 age educ region sex race&lt;BR /&gt;rincome income occ10 prestg10 indus10 size worda wordB wordc wordd worde wordf wordg wordh wordi wordj wordsum wtssall);&lt;/P&gt;&lt;P&gt;Array worddata (10)$ worda --wordj; /*wordsum not included because 9 is a value and not missin*/&lt;BR /&gt;Do i= 1 to 10;&lt;BR /&gt;if worddata(i)in (9,-1)then worddata (i)=.;&lt;BR /&gt;/*Where year=1988*/&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Proc freq data=work.worddata2;&lt;BR /&gt;Table year*worda--wordsum;&lt;BR /&gt;weight wtssall;&lt;BR /&gt;Run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data work.worddatamacro;&lt;BR /&gt;set work.worddata2;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro wordscore(year);&lt;BR /&gt;proc sort data=work.worddatamacro; by year; run;&lt;/P&gt;&lt;P&gt;*read following data;&lt;BR /&gt;proc freq data=work.worddatamacro;&lt;BR /&gt;where year=&amp;amp;year.;&lt;BR /&gt;tables worda--wordsum;&lt;BR /&gt;title 'Word Score for &amp;amp;year.';&lt;BR /&gt;run;&lt;BR /&gt;%mend wordscore;&lt;/P&gt;&lt;P&gt;data worddata3; set work.worddatamacro;Run;&lt;/P&gt;&lt;P&gt;%wordscore(1988);&lt;/P&gt;&lt;P&gt;%macro wordscore (year);&lt;BR /&gt;%Do i=1974 %to 1984 %by 2; %wordscore(year=&amp;amp;i.) %end;&lt;BR /&gt;%Do i=1987 %to 1994 %by 1; %wordscore(year=&amp;amp;i.) %end;&lt;BR /&gt;%Do i=1996 %to 2000 %by 2; %wordscore(year=&amp;amp;i.) %end;&lt;BR /&gt;%Do i=2004 %to 2018 %by 2; %wordscore(year=&amp;amp;i.) %end;&lt;/P&gt;&lt;P&gt;%mend wordscore;&lt;BR /&gt;%wordscore;&lt;BR /&gt;Ods rtf close;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 20 Oct 2020 18:03:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-an-array-into-a-looping-macro-program/m-p/692976#M211221</guid>
      <dc:creator>kim_trevino1</dc:creator>
      <dc:date>2020-10-20T18:03:03Z</dc:date>
    </item>
    <item>
      <title>Re: converting an array into a looping macro program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-an-array-into-a-looping-macro-program/m-p/692983#M211226</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;This was an assignment I had from a few weeks ago that I don't think I did correctly.&amp;nbsp; Part three looping macros is what is giving me trouble. Can someone tell me where I am going wrong?&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;We don't have your data sets, and I'm not going to go line by line through your code to figure out what you mean. You can't simply ask "where I am going wrong?", because we don't know what is wrong, and we need specific information about what you think (or what SAS thinks) is wrong.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Please run your code again with this line at the top&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;We need to see the LOG. We need to see the LOG &lt;STRONG&gt;properly formatted&lt;/STRONG&gt; so we can read it. You do this by copying it as text and pasting it into the window that appears when you click on the &amp;lt;/&amp;gt; icon. DO NOT SKIP THIS STEP. Otherwise, we get a badly formatted log which is of no use to us.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Lastly, I am somewhat annoyed at your professor, as repeating analyses over years is not really something you want to do with macros. Using a BY statement is a much simpler method. Teaching to do this via macros positively re-inforces bad practices.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Oct 2020 18:42:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-an-array-into-a-looping-macro-program/m-p/692983#M211226</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-10-20T18:42:38Z</dc:date>
    </item>
    <item>
      <title>Re: converting an array into a looping macro program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-an-array-into-a-looping-macro-program/m-p/692986#M211227</link>
      <description>&lt;P&gt;Why do you have two definitions for the same macro? That way lies madness as you may not know which version is running.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Defining a macro and calling the same macro inside the macro also seems like a descent into madness would follow.&lt;/P&gt;
&lt;PRE&gt;%macro wordscore (year);
%Do i=1974 %to 1984 %by 2; %wordscore(year=&amp;amp;i.) %end;
%Do i=1987 %to 1994 %by 1; %wordscore(year=&amp;amp;i.) %end;
%Do i=1996 %to 2000 %by 2; %wordscore(year=&amp;amp;i.) %end;
%Do i=2004 %to 2018 %by 2; %wordscore(year=&amp;amp;i.) %end;

%mend wordscore;&lt;/PRE&gt;</description>
      <pubDate>Tue, 20 Oct 2020 19:10:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-an-array-into-a-looping-macro-program/m-p/692986#M211227</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-10-20T19:10:39Z</dc:date>
    </item>
    <item>
      <title>Re: converting an array into a looping macro program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-an-array-into-a-looping-macro-program/m-p/692987#M211228</link>
      <description>&lt;P&gt;The professors question and hint are as clear as mud.&lt;/P&gt;
&lt;P&gt;You need two macros. One that works for one specific year.&lt;/P&gt;
&lt;P&gt;Then a second one that has the %DO loop and then calls the first one.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You seemed to create the first one, but then instead of making a second one you replaced the first one.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro one_year(year);
 .... put actual code here ...
%mend ;

%macro mutliple_years(start,end,increment);
%local year;
%do year=&amp;amp;start %to &amp;amp;end %by &amp;amp;increment;
   %one_year(&amp;amp;year)
%end;
%mend multiple_years;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Oct 2020 19:12:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-an-array-into-a-looping-macro-program/m-p/692987#M211228</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-10-20T19:12:24Z</dc:date>
    </item>
    <item>
      <title>Re: converting an array into a looping macro program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-an-array-into-a-looping-macro-program/m-p/693183#M211329</link>
      <description>&lt;PRE&gt;      Licensed to BAYLOR UNIVERSITY - SFA - T&amp;amp;R, Site 70092987.
NOTE: This session is executing on the X64_10PRO  platform.



NOTE: Analytical products:

      SAS/STAT 15.1
      SAS/ETS 15.1
      SAS/IML 15.1
      SAS/QC 15.1

NOTE: Additional host information:

 X64_10PRO WIN 10.0.18362  Workstation

NOTE: SAS initialization used:
      real time           1.00 seconds
      cpu time            0.54 seconds

1    libname in "C:\Users\kim_trevino1\Desktop\Advanced STATS 2020";
NOTE: Libref IN was successfully assigned as follows:
      Engine:        V9
      Physical Name: C:\Users\kim_trevino1\Desktop\Advanced STATS 2020
1  !                                                                 run;
2
3    *options symbolgen;
4    options mprint;
5    Data work.worddata2;
6        set in.gss7218_r3(Keep= Year ID marital wrkstat hrs1 age educ region sex race
7    rincome income occ10 prestg10 indus10 size worda wordB wordc wordd worde wordf wordg wordh
7  ! wordi wordj wordsum wtssall);
8
9    Array worddata (10)$ worda --wordj;  /*wordsum not included because 9 is a value and not
9  ! missin*/
10   Do i= 1 to 10;
11   if worddata(i)in (9,-1)then worddata (i)=.;
12   /*Where year=1988*/
13   end;
14   run;

NOTE: There were 64814 observations read from the data set IN.GSS7218_R3.
NOTE: The data set WORK.WORDDATA2 has 64814 observations and 29 variables.
NOTE: DATA statement used (Total process time):
      real time           3.86 seconds
      cpu time            1.39 seconds


15   ibname in "C:\Users\kim_trevino1\Desktop\Advanced STATS 2020";
     ------
     14
NOTE: Libref IN was successfully assigned as follows:
      Engine:        V9
      Physical Name: C:\Users\kim_trevino1\Desktop\Advanced STATS 2020
WARNING 14-169: Assuming the symbol LIBNAME was misspelled as ibname.

16
17   *options symbolgen;
18   options mprint; run;
19   Data work.worddata2;
20       set in.gss7218_r3(Keep= Year ID marital wrkstat hrs1 age educ region sex race
21   rincome income occ10 prestg10 indus10 size worda wordB wordc wordd worde wordf wordg wordh
21 ! wordi wordj wordsum wtssall);
22
23   Array worddata (10)$ worda --wordj;  /*wordsum not included because 9 is a value and not
23 ! missin*/
24   Do i= 1 to 10;
25   if worddata(i)in (9,-1)then worddata (i)=.;
26   /*Where year=1988*/
27   end;
28   run;

NOTE: There were 64814 observations read from the data set IN.GSS7218_R3.
NOTE: The data set WORK.WORDDATA2 has 64814 observations and 29 variables.
NOTE: DATA statement used (Total process time):
      real time           2.91 seconds
      cpu time            1.07 seconds


29   Proc freq data=work.worddata2;
30   Table year*worda--wordsum;
31   weight wtssall;
32   Run;

NOTE: Writing HTML Body file: sashtml.htm
NOTE: There were 64814 observations read from the data set WORK.WORDDATA2.
NOTE: PROCEDURE FREQ used (Total process time):
      real time           1.09 seconds
      cpu time            0.68 seconds


33
34   Data work.worddatamacro;
35   set work.worddata2;
36   run;

NOTE: There were 64814 observations read from the data set WORK.WORDDATA2.
NOTE: The data set WORK.WORDDATAMACRO has 64814 observations and 29 variables.
NOTE: DATA statement used (Total process time):
      real time           0.02 seconds
      cpu time            0.01 seconds


37
38   %macro wordscore(year);
39   proc sort data=work.worddatamacro; by year; run;
40
41   *read following data;
42   proc freq data=work.worddatamacro;
43       where year=&amp;amp;year.;
44       tables worda--wordsum;
45       title 'Word Score for &amp;amp;year.';
46   run;
47   %mend wordscore;
48
49   data worddata3; set work.worddata2;Run;

NOTE: There were 64814 observations read from the data set WORK.WORDDATA2.
NOTE: The data set WORK.WORDDATA3 has 64814 observations and 29 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


50
51   %wordscore(1988);
MPRINT(WORDSCORE):   proc sort data=work.worddatamacro;
MPRINT(WORDSCORE):   by year;
MPRINT(WORDSCORE):   run;

NOTE: There were 64814 observations read from the data set WORK.WORDDATAMACRO.
NOTE: The data set WORK.WORDDATAMACRO has 64814 observations and 29 variables.
NOTE: PROCEDURE SORT used (Total process time):
      real time           0.03 seconds
      cpu time            0.03 seconds


MPRINT(WORDSCORE):   *read following data;
MPRINT(WORDSCORE):   proc freq data=work.worddatamacro;
MPRINT(WORDSCORE):   where year=1988;
MPRINT(WORDSCORE):   tables worda--wordsum;
MPRINT(WORDSCORE):   title 'Word Score for &amp;amp;year.';
MPRINT(WORDSCORE):   run;
NOTE: There were 1481 observations read from the data set WORK.WORDDATAMACRO.
      WHERE year=1988;
NOTE: PROCEDURE FREQ used (Total process time):
      real time           0.05 seconds
      cpu time            0.03 seconds


52   Data work.worddatamacro2;
53   set work.worddata3;
54   run;

NOTE: There were 64814 observations read from the data set WORK.WORDDATA3.
NOTE: The data set WORK.WORDDATAMACRO2 has 64814 observations and 29 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


55   %macro loopyear (year);
56       %Do i=1974 %to 1984 %by 2; %loopyear(year=&amp;amp;i.) %end;
57       %Do i=1987 %to 1994 %by 1; %loopyear(year=&amp;amp;i.) %end;
58       %Do i=1996 %to 2018 %by 2; %loopyear(year=&amp;amp;i.) %end;
59       run;
60
61   %mend loopyear;
62   data worddata4; set work.worddatamacro2;Run;

NOTE: There were 64814 observations read from the data set WORK.WORDDATAMACRO2.
NOTE: The data set WORK.WORDDATA4 has 64814 observations and 29 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


63   %loopyear (year);&lt;/PRE&gt;&lt;P&gt;So after this step, part three of the assignment, it does nothing. It just spins its wheels for eternity.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The data set is the GSS, if that helps, and I'm using his notes and the little sas book to code.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you, Paige, for helping me. I was a little intimidated, reaching out for help. The assignment is over, but I want to make sure I understand how to code a macro correctly. I will be analyzing panel data soon&lt;SPAN style="font-family: inherit;"&gt;, so it is useful to know that this might not be the best way. Do you mind explaining why macros are inappropriate for this task or pointing me in the direction of a good resource?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;Thank you again.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Oct 2020 14:05:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-an-array-into-a-looping-macro-program/m-p/693183#M211329</guid>
      <dc:creator>kim_trevino1</dc:creator>
      <dc:date>2020-10-21T14:05:44Z</dc:date>
    </item>
    <item>
      <title>Re: converting an array into a looping macro program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-an-array-into-a-looping-macro-program/m-p/693185#M211330</link>
      <description>&lt;P&gt;As I explained, if you want perform the same analysis on each year, virtually every SAS PROC has a BY statement which eliminates the need for macro loops. You use BY YEAR; in the PROC.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Oct 2020 14:08:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-an-array-into-a-looping-macro-program/m-p/693185#M211330</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-10-21T14:08:10Z</dc:date>
    </item>
    <item>
      <title>Re: converting an array into a looping macro program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-an-array-into-a-looping-macro-program/m-p/693192#M211333</link>
      <description>&lt;P&gt;Thank you, Ballardw. The TA helped me write this. I wish I could explain why, but I wasn't aware the texts was defining the same macro twice.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you instruct me&amp;nbsp;on how to write this better?&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%Do i=1974 %to 1984 %by 2; %end;&lt;/PRE&gt;&lt;P&gt;Is the text above all I need?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Oct 2020 14:14:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-an-array-into-a-looping-macro-program/m-p/693192#M211333</guid>
      <dc:creator>kim_trevino1</dc:creator>
      <dc:date>2020-10-21T14:14:56Z</dc:date>
    </item>
    <item>
      <title>Re: converting an array into a looping macro program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-an-array-into-a-looping-macro-program/m-p/693193#M211334</link>
      <description>&lt;P&gt;Thank you, Tom. I will try this and get back to you. The problem with learning a new language (SAS) is that I know I have questions, but I'm not sure how to ask them clearly.&amp;nbsp; I'm left asking, "How do I make the thing work?"hahaha.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Oct 2020 14:18:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-an-array-into-a-looping-macro-program/m-p/693193#M211334</guid>
      <dc:creator>kim_trevino1</dc:creator>
      <dc:date>2020-10-21T14:18:43Z</dc:date>
    </item>
    <item>
      <title>Re: converting an array into a looping macro program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-an-array-into-a-looping-macro-program/m-p/693194#M211335</link>
      <description>&lt;P&gt;Okay, thank you.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Oct 2020 14:20:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-an-array-into-a-looping-macro-program/m-p/693194#M211335</guid>
      <dc:creator>kim_trevino1</dc:creator>
      <dc:date>2020-10-21T14:20:57Z</dc:date>
    </item>
    <item>
      <title>Re: converting an array into a looping macro program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-an-array-into-a-looping-macro-program/m-p/693204#M211337</link>
      <description>&lt;P&gt;This part of the code does not look right.&lt;/P&gt;
&lt;PRE&gt;55   %macro loopyear (year);
56       %Do i=1974 %to 1984 %by 2; %loopyear(year=&amp;amp;i.) %end;
57       %Do i=1987 %to 1994 %by 1; %loopyear(year=&amp;amp;i.) %end;
58       %Do i=1996 %to 2018 %by 2; %loopyear(year=&amp;amp;i.) %end;
59       run;
60
61   %mend loopyear;
62   data worddata4; set work.worddatamacro2;Run;

NOTE: There were 64814 observations read from the data set WORK.WORDDATAMACRO2.
NOTE: The data set WORK.WORDDATA4 has 64814 observations and 29 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


63   %loopyear (year);&lt;/PRE&gt;
&lt;P&gt;First you defined the macro LOOPYEAR to take parameter named YEAR, and&amp;nbsp;when you called it you assigned the YEAR parameter the text string year instead of a real value.&amp;nbsp; But since the macro is not using the YEAR parameter in any way that actually doesn't matter.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second you are calling your same macro LOOPYEAR recursively.&amp;nbsp; So it will keep calling itself until SAS runs out of memory.&amp;nbsp; You need to change the calls to LOOPYEAR inside the definition of the macro LOOPYEAR to call the macro WORDSCORE.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Oct 2020 14:45:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-an-array-into-a-looping-macro-program/m-p/693204#M211337</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-10-21T14:45:11Z</dc:date>
    </item>
  </channel>
</rss>

