<?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: macro and do loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/macro-and-do-loop/m-p/612337#M178658</link>
    <description>&lt;P&gt;I think what you want is :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&amp;amp;SUB._CAT[j]=symget(cats('CAT', J));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let cat1=x;
%let cat2=y;
%let cat3=z;

data have;
array c $ c1-c3;
do j=1 to 3;
    c(j)=symget(cats('cat',j));
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But as &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt; has pointed, there is probably a better non macro solution to your problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 17 Dec 2019 09:00:45 GMT</pubDate>
    <dc:creator>gamotte</dc:creator>
    <dc:date>2019-12-17T09:00:45Z</dc:date>
    <item>
      <title>macro and do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-and-do-loop/m-p/612249#M178602</link>
      <description>&lt;P&gt;Hello members,&lt;/P&gt;
&lt;P&gt;I created macro variable (CAT1) from proc sql select into. And want to use it in the data step in the do loop:&amp;nbsp;&lt;FONT color="#800000"&gt;&amp;amp;SUB._CAT[J]=&amp;amp;&amp;amp;CAT&amp;amp;J.;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;It does not work. Where did I do wrong? Thanks!&lt;/P&gt;
&lt;P&gt;-----------------&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;select rc into :CAT1 from rc2 where Objective_1="&amp;amp;subj." and Question_No='11';&lt;BR /&gt;quit;&lt;BR /&gt;%put RC1 = &amp;amp;CAT1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data tpsalt3;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;set tpsalt2;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;array &amp;amp;SUB._CAT {&amp;amp;ITEM_TOT.} $ &amp;amp;SUB._CAT1-&amp;amp;SUB._CAT&amp;amp;ITEM_TOT.;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;do J=1 to &amp;amp;ITEM_TOT.;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;FONT color="#800000"&gt; &amp;amp;SUB._CAT[J]=&amp;amp;&amp;amp;CAT&amp;amp;J.;&lt;/FONT&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;drop J; &lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Dec 2019 22:56:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-and-do-loop/m-p/612249#M178602</guid>
      <dc:creator>TX_STAR</dc:creator>
      <dc:date>2019-12-16T22:56:04Z</dc:date>
    </item>
    <item>
      <title>Re: macro and do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-and-do-loop/m-p/612251#M178604</link>
      <description>&lt;P&gt;I think you have created a rather difficult to understand combination of macros and arrays and it would be helpful if you explained what you are doing in words.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Next, you need to create working valid SAS code WITHOUT macros and WITHOUT macro variables for one or two cases. If you don't have working valid SAS code without macros and without macro variables, you will never get it to work with macros. Show us the working code without macro language.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Lastly, I doubt that macros are needed here, I simply don't see why you don't use arrays and stop there.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Dec 2019 23:01:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-and-do-loop/m-p/612251#M178604</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-12-16T23:01:20Z</dc:date>
    </item>
    <item>
      <title>Re: macro and do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-and-do-loop/m-p/612254#M178607</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;Where did I go wrong?"&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Lack of understanding when macro code gets executed, and incorrect intermixing of macro and data step statements.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In summary, (in general) macro is just text substitution &lt;STRONG&gt;before the data step even starts executing.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;proc sql;&lt;BR /&gt;select rc into :CAT1 from rc2 where Objective_1="&amp;amp;subj." and Question_No='11';&lt;BR /&gt;quit;&lt;BR /&gt;%put RC1 = &amp;amp;CAT1;&amp;nbsp; &amp;lt;&amp;lt;&amp;lt; all this would do is cause confusion.&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Post the value of &amp;amp;CAT.&amp;nbsp; And does the where clause guarantee a single row is returned?&amp;nbsp; If not, you probably want separated by ' ' in your SQL statement.&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;%put &amp;amp;=cat1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;data tpsalt3;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;set tpsalt2;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;array &amp;amp;SUB._CAT {&amp;amp;ITEM_TOT.} $ &amp;amp;SUB._CAT1-&amp;amp;SUB._CAT&amp;amp;ITEM_TOT.;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;do J=1 to &amp;amp;ITEM_TOT.;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;FONT color="#800000"&gt; &amp;amp;SUB._CAT[J]=&amp;amp;&amp;amp;CAT&amp;amp;J.;&lt;/FONT&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;drop J; &lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you really have an unknown number of columns in your source dataset?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suspect your data step could be written without macro at all:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data tpsalt3;
&amp;nbsp; &amp;nbsp;set tpsalt2;

&amp;nbsp; &amp;nbsp;array ary{*} myvar:;

&amp;nbsp; &amp;nbsp;do J=1 to dim(ary);
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;amp;SUB._CAT[J]=&amp;amp;&amp;amp;CAT&amp;amp;J.;  * &amp;lt;&amp;lt;&amp;lt; my guess is this line will never work! ;
      ary{j}=???;  * &amp;lt;&amp;lt;&amp;lt; what are you trying to do here? ;
&amp;nbsp; &amp;nbsp;end;

drop J; 
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Otherwise, explain what you're trying to do, and see if you can do it without macro, which i suspect you can.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Dec 2019 23:09:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-and-do-loop/m-p/612254#M178607</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2019-12-16T23:09:13Z</dc:date>
    </item>
    <item>
      <title>Re: macro and do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-and-do-loop/m-p/612317#M178646</link>
      <description>&lt;P&gt;You seem to want to use a series of macro variables (indicated by the indirect reference &amp;amp;&amp;amp;CAT&amp;amp;J), but create only CAT1. That won't work in the first place.&lt;/P&gt;
&lt;P&gt;I am about 100% confident you don't need any macro programming here at all. Please post example data for tpsalt2 and rc2 in data steps with datalines, and what you want to get out of it in tpsalt3.&lt;/P&gt;
&lt;P&gt;Please also provide what is contained in macro variables SUB and SUBJ.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put RC1 = &amp;amp;CAT1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is also a VERY BAD idea, as it will mislead anyone (including you!) looking at the log.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Dec 2019 06:58:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-and-do-loop/m-p/612317#M178646</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-12-17T06:58:57Z</dc:date>
    </item>
    <item>
      <title>Re: macro and do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-and-do-loop/m-p/612337#M178658</link>
      <description>&lt;P&gt;I think what you want is :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&amp;amp;SUB._CAT[j]=symget(cats('CAT', J));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let cat1=x;
%let cat2=y;
%let cat3=z;

data have;
array c $ c1-c3;
do j=1 to 3;
    c(j)=symget(cats('cat',j));
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But as &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt; has pointed, there is probably a better non macro solution to your problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Dec 2019 09:00:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-and-do-loop/m-p/612337#M178658</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2019-12-17T09:00:45Z</dc:date>
    </item>
    <item>
      <title>Re: macro and do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-and-do-loop/m-p/612343#M178660</link>
      <description>&lt;P&gt;Also, as already said, you only create a macrovariable &amp;amp;CAT1. though it seems you&lt;/P&gt;
&lt;P&gt;want to loop on several values.&lt;/P&gt;
&lt;P&gt;Perhaps you want something as follows :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data cat;
input cat $;
cards;
X
y
z
;
run;

proc sql;
SELECT cat INTO :cat1-:cat3
FROM cat;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 17 Dec 2019 09:25:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-and-do-loop/m-p/612343#M178660</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2019-12-17T09:25:20Z</dc:date>
    </item>
    <item>
      <title>Re: macro and do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-and-do-loop/m-p/612425#M178701</link>
      <description>&lt;P&gt;I am sorry for confusing question.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have item category variable rc in data rc2. Using the objective_1 and Question_No variables, I can subset the item category info for 10 items.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have student responses to 10 items (10 variables) in data tpsalt3.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to abstract the item category information (in rc variable in rc2 dataset) and converted to 10 item category variable (cat1....cat10) and merge to tpsalt3 so that I have item response and item category variables all in one data set.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the code that I posted, I wanted to abstract item category information from variable rc in dataset rc2 using marco variables. To same space, I only posted one proc sql; select into;&amp;nbsp; instead of 10. (misleading information #1).&lt;/P&gt;
&lt;P&gt;The I wanted to create 10 item category variables (&amp;amp;sub._cat1 - &amp;amp;sub._cat10) using loop in data step. I mixed macro with data step loop (misleading information #2).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think, I can directly create 10 item category variables from rc2 by subset and transpose variable rc then directly merge to tpsalts.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Which way is better for this purpose?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thanks a lot for your responses!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Dec 2019 15:16:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-and-do-loop/m-p/612425#M178701</guid>
      <dc:creator>TX_STAR</dc:creator>
      <dc:date>2019-12-17T15:16:24Z</dc:date>
    </item>
    <item>
      <title>Re: macro and do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-and-do-loop/m-p/612437#M178707</link>
      <description>&lt;P&gt;Please provide example data in a data step with datalines, and the expected result.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Dec 2019 15:59:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-and-do-loop/m-p/612437#M178707</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-12-17T15:59:59Z</dc:date>
    </item>
    <item>
      <title>Re: macro and do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-and-do-loop/m-p/612441#M178710</link>
      <description>&lt;P&gt;data rc2&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.RC_L" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r header" scope="col"&gt;Obs&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;Question_No&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;rc&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;1&lt;/TH&gt;
&lt;TD class="l data"&gt;11&lt;/TD&gt;
&lt;TD class="l data"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;2&lt;/TH&gt;
&lt;TD class="l data"&gt;12&lt;/TD&gt;
&lt;TD class="l data"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;3&lt;/TH&gt;
&lt;TD class="l data"&gt;13&lt;/TD&gt;
&lt;TD class="l data"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;4&lt;/TH&gt;
&lt;TD class="l data"&gt;14&lt;/TD&gt;
&lt;TD class="l data"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;5&lt;/TH&gt;
&lt;TD class="l data"&gt;15&lt;/TD&gt;
&lt;TD class="l data"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;6&lt;/TH&gt;
&lt;TD class="l data"&gt;16&lt;/TD&gt;
&lt;TD class="l data"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;7&lt;/TH&gt;
&lt;TD class="l data"&gt;17&lt;/TD&gt;
&lt;TD class="l data"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;8&lt;/TH&gt;
&lt;TD class="l data"&gt;18&lt;/TD&gt;
&lt;TD class="l data"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;9&lt;/TH&gt;
&lt;TD class="l data"&gt;19&lt;/TD&gt;
&lt;TD class="l data"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;10&lt;/TH&gt;
&lt;TD class="l data"&gt;20&lt;/TD&gt;
&lt;TD class="l data"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;data tpsalt3&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.TPSALT3" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="l header" scope="col"&gt;ID&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;S_ITEM1&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;S_ITEM2&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;S_ITEM3&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;S_ITEM4&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;S_ITEM5&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;S_ITEM6&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;S_ITEM7&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;S_ITEM8&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;S_ITEM9&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;S_ITEM10&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;the S_CAT1 - S_CAT10 will have values from variable rc in data rc2: 1111122112 for every student. S_ITEM1 -S_ITEM10 have student responses.&amp;nbsp;&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.TPSALT3" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="l header" scope="col"&gt;ID&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;S_ITEM1&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;S_ITEM2&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;S_ITEM3&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;S_ITEM4&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;S_ITEM5&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;S_ITEM6&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;S_ITEM7&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;S_ITEM8&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;S_ITEM9&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;S_ITEM10&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;S_CAT1&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;S_CAT2&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;S_CAT3&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;S_CAT4&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;S_CAT5&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;S_CAT6&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;S_CAT7&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;S_CAT8&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;S_CAT9&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;S_CAT10&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Tue, 17 Dec 2019 16:18:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-and-do-loop/m-p/612441#M178710</guid>
      <dc:creator>TX_STAR</dc:creator>
      <dc:date>2019-12-17T16:18:44Z</dc:date>
    </item>
    <item>
      <title>Re: macro and do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-and-do-loop/m-p/612443#M178712</link>
      <description>&lt;P&gt;Just use PROC TRANSPOSE to convert your tall/skinny data into short/wide data.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=rc2 out=want prefix=S_ITEM;
  id question_no;
  var rc;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Your real data probably has groups of values for each participant.&amp;nbsp; So you will probably want to include the variable(s) that identify each group in a BY statement.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Dec 2019 16:23:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-and-do-loop/m-p/612443#M178712</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-12-17T16:23:19Z</dc:date>
    </item>
    <item>
      <title>Re: macro and do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-and-do-loop/m-p/612461#M178720</link>
      <description>&lt;P&gt;The transposed item category data has 10 variables, one record, no ID variable. How to do the many to one merge so that in the new data set every student record has 10 populated item category variables (S_CAT1-S_CAT10). When use merge, only the first record has item category values. The 10 variables (S_CAT1-S_CAT10) are empty for all records other than the first one.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Dec 2019 17:04:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-and-do-loop/m-p/612461#M178720</guid>
      <dc:creator>TX_STAR</dc:creator>
      <dc:date>2019-12-17T17:04:33Z</dc:date>
    </item>
    <item>
      <title>Re: macro and do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-and-do-loop/m-p/612470#M178722</link>
      <description>&lt;P&gt;Show what code you used as most methods will retain the values from the "short" dataset.&lt;/P&gt;
&lt;P&gt;If you know that your dataset just has one observations then write your data step to read it just once.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  set have ;
  if _n_=1 then set s_items;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Just make sure that the variable S_ITEMS are not also in HAVE because if they are then when you read the second value from HAVE it will overwrite whatever was read from S_ITEMS.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Dec 2019 17:12:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-and-do-loop/m-p/612470#M178722</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-12-17T17:12:08Z</dc:date>
    </item>
    <item>
      <title>Re: macro and do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-and-do-loop/m-p/612514#M178754</link>
      <description>have only has one record (and 10 variables s_cat1 - s_cat10). s_items have student responses (many records). dataset Have does not have s_items variable.&lt;BR /&gt;I used &lt;BR /&gt;data want;&lt;BR /&gt;   merge have s_items;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;I didn't work. The want data set has all variables but the first record of s_cat1 - s_cat10 have values. The rest are empty.&lt;BR /&gt;Why use  if _n_=1 then set s_items;</description>
      <pubDate>Tue, 17 Dec 2019 19:16:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-and-do-loop/m-p/612514#M178754</guid>
      <dc:creator>TX_STAR</dc:creator>
      <dc:date>2019-12-17T19:16:07Z</dc:date>
    </item>
    <item>
      <title>Re: macro and do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-and-do-loop/m-p/612517#M178755</link>
      <description>&lt;P&gt;I would use the IF _N_=1 because then the code shows what you are doing. Most SAS programmers would consider a merge statement without a BY statement as an indication of a coding error because of the missing BY statement.&amp;nbsp; And without the BY statement SAS does not retain the values from the short dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But either way you cannot the variables on both input datasets.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Examine the output for the BOTH and RIGHT variables from the TEST1 and TEST2 datasets in this example.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data long;
  input id left both ;
cards;
1 1 1
2 2 2
3 3 3
;

data short;
  input both right;
cards;
4 4
;

data test1 ;
  merge long short;
run;

proc print;
run;

data test2 ;
  set long ;
  if _n_=1 then set short;
run;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;SAS 9.4 on WINDOWS

Obs    id    left    both    right

 1      1      1       4       4
 2      2      2       2       .
 3      3      3       3       .

SAS 9.4 on WINDOWS

Obs    id    left    both    right

 1      1      1       4       4
 2      2      2       2       4
 3      3      3       3       4
&lt;/PRE&gt;</description>
      <pubDate>Tue, 17 Dec 2019 19:38:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-and-do-loop/m-p/612517#M178755</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-12-17T19:38:06Z</dc:date>
    </item>
    <item>
      <title>Re: macro and do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-and-do-loop/m-p/612549#M178769</link>
      <description>Thanks so much for the explanation!</description>
      <pubDate>Tue, 17 Dec 2019 22:20:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-and-do-loop/m-p/612549#M178769</guid>
      <dc:creator>TX_STAR</dc:creator>
      <dc:date>2019-12-17T22:20:19Z</dc:date>
    </item>
    <item>
      <title>Re: macro and do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-and-do-loop/m-p/612847#M178913</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;Please provide example data in a data step with datalines, and the expected result.&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&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/7661"&gt;@TX_STAR&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;data rc2&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.RC_L" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r header" scope="col"&gt;Obs&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;Question_No&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;rc&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;1&lt;/TH&gt;
&lt;TD class="l data"&gt;11&lt;/TD&gt;
&lt;TD class="l data"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;2&lt;/TH&gt;
&lt;TD class="l data"&gt;12&lt;/TD&gt;
&lt;TD class="l data"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;3&lt;/TH&gt;
&lt;TD class="l data"&gt;13&lt;/TD&gt;
&lt;TD class="l data"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;4&lt;/TH&gt;
&lt;TD class="l data"&gt;14&lt;/TD&gt;
&lt;TD class="l data"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;5&lt;/TH&gt;
&lt;TD class="l data"&gt;15&lt;/TD&gt;
&lt;TD class="l data"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;6&lt;/TH&gt;
&lt;TD class="l data"&gt;16&lt;/TD&gt;
&lt;TD class="l data"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;7&lt;/TH&gt;
&lt;TD class="l data"&gt;17&lt;/TD&gt;
&lt;TD class="l data"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;8&lt;/TH&gt;
&lt;TD class="l data"&gt;18&lt;/TD&gt;
&lt;TD class="l data"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;9&lt;/TH&gt;
&lt;TD class="l data"&gt;19&lt;/TD&gt;
&lt;TD class="l data"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;10&lt;/TH&gt;
&lt;TD class="l data"&gt;20&lt;/TD&gt;
&lt;TD class="l data"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;data tpsalt3&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.TPSALT3" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="l header" scope="col"&gt;ID&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;S_ITEM1&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;S_ITEM2&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;S_ITEM3&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;S_ITEM4&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;S_ITEM5&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;S_ITEM6&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;S_ITEM7&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;S_ITEM8&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;S_ITEM9&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;S_ITEM10&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;the S_CAT1 - S_CAT10 will have values from variable rc in data rc2: 1111122112 for every student. S_ITEM1 -S_ITEM10 have student responses.&amp;nbsp;&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.TPSALT3" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="l header" scope="col"&gt;ID&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;S_ITEM1&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;S_ITEM2&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;S_ITEM3&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;S_ITEM4&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;S_ITEM5&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;S_ITEM6&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;S_ITEM7&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;S_ITEM8&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;S_ITEM9&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;S_ITEM10&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;S_CAT1&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;S_CAT2&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;S_CAT3&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;S_CAT4&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;S_CAT5&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;S_CAT6&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;S_CAT7&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;S_CAT8&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;S_CAT9&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;S_CAT10&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I appreciate the additional information, but how is this compliant with what Kurt requested?&amp;nbsp; How can we cut-and-paste this ... "stuff" ... into SAS, run with it, and provide you tested code that works?&amp;nbsp; Do you know how to write a data step using the datalines statement?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Help us help you by learning how to post a good question.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Dec 2019 21:12:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-and-do-loop/m-p/612847#M178913</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2019-12-18T21:12:26Z</dc:date>
    </item>
    <item>
      <title>Re: macro and do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-and-do-loop/m-p/613067#M179003</link>
      <description>&lt;P&gt;Sorry for the unclear message.&lt;/P&gt;
&lt;P&gt;Here is the example data:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data rc has one record.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data rc;
   input cat1 - cat10;
   cards;
   1 1 1 1 1 2 2 1 1 1
   ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;data tps has many records (only show 10 here).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data tps;
   input id it1 - it10;
   cards;
   1 1 2 3 1 1 1 3 4 5 4
   2 2 2 3 1 3 1 3 4 5 5
   3 3 2 2 2 3 1 2 4 4 4
   4 3 2 2 4 3 1 2 4 5 4
   5 3 2 2 2 3 1 2 4 4 4
   6 3 2 2 4 3 1 2 4 5 4
   7 3 2 2 2 3 1 2 4 4 4
   8 3 2 2 4 3 1 2 4 5 4
   9 3 2 2 2 3 1 2 4 4 4
  10 3 2 2 4 3 1 2 4 5 4
  ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;data want is the data I need which has as many records as data tps. The values for cat1-cat10 are all the same for all records.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   input id it1-it10 cat1-cat10;
   cards;
   1 1 2 3 1 1 1 3 4 5 4 1 1 1 1 1 2 2 1 1 1
   2 2 2 3 1 3 1 3 4 5 5 1 1 1 1 1 2 2 1 1 1
   3 3 2 2 2 3 1 2 4 4 4 1 1 1 1 1 2 2 1 1 1
   4 3 2 2 4 3 1 2 4 5 4 1 1 1 1 1 2 2 1 1 1
   5 3 2 2 2 3 1 2 4 4 4 1 1 1 1 1 2 2 1 1 1
   6 3 2 2 4 3 1 2 4 5 4 1 1 1 1 1 2 2 1 1 1
   7 3 2 2 2 3 1 2 4 4 4 1 1 1 1 1 2 2 1 1 1
   8 3 2 2 4 3 1 2 4 5 4 1 1 1 1 1 2 2 1 1 1
   9 3 2 2 2 3 1 2 4 4 4 1 1 1 1 1 2 2 1 1 1
  10 3 2 2 4 3 1 2 4 5 4 1 1 1 1 1 2 2 1 1 1
  ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Initially, I used proc sql; select into to create 10 macro variables to be used in the next data step to create the cat1-cat10 variables in the want dataset. I mixed the macro variable with do loop which did not work. If I do want to use macro variables created with proc sql to create cat1-cat10 at data step, how should I do?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Dec 2019 15:20:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-and-do-loop/m-p/613067#M179003</guid>
      <dc:creator>TX_STAR</dc:creator>
      <dc:date>2019-12-19T15:20:31Z</dc:date>
    </item>
    <item>
      <title>Re: macro and do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-and-do-loop/m-p/613070#M179005</link>
      <description>&lt;P&gt;Not sure what macro variables would do to help.&amp;nbsp; You can just combine the two datasets.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set tps;
  if _n_=1 then set rc;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But what is the overall goal here?&amp;nbsp; Are you going to "grade" the response (TPS) based on whether they agree with the answer key (RC)?&lt;/P&gt;
&lt;P&gt;Something like this which will compute SCORE as a count of how many of the 10 pairs of values match.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set tps;
  if _n_=1 then set rc;
  array key cat1-cat10;
  array answer it1-it10;
  do index=1 to dim(key);
      score=sum(score,key[index]=answer[index]);
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 Dec 2019 15:28:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-and-do-loop/m-p/613070#M179005</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-12-19T15:28:47Z</dc:date>
    </item>
  </channel>
</rss>

