<?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 Handle multiple proc transpose in one macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Handle-multiple-proc-transpose-in-one-macro/m-p/625425#M184324</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro pull(report,ln,col);

data have;
length ln $25.;
input ln cnt cnt2;
datalines;
4544 2 1
4544 3 1
4544 4 1
4544 5 1
4465 10 1
4465 5 1
4475 1 0
4475 2 0
4475 3 1
;

proc sort data=have;
by ln;
run;

proc sql;
create table &amp;amp;report. as
select ln cnt cnt2
from have
;
quit;

proc transpose data=&amp;amp;report.;
by &amp;amp;ln.;
var cnt cnt2;
run;

data &amp;amp;report (rename=(COL1=&amp;amp;col));
set have2;
run;

%mend pull;

%pull(_4544,4544,Mth1);
%pull(_4465,4465,Mth2);
%pull(_4475,4475,Mth3);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;Is there a way to have 3 different datasets handled in 1 macro separated by the ln and label the col1 in the proc transpose without 3 different datasets??&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 18 Feb 2020 08:47:57 GMT</pubDate>
    <dc:creator>Q1983</dc:creator>
    <dc:date>2020-02-18T08:47:57Z</dc:date>
    <item>
      <title>Handle multiple proc transpose in one macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Handle-multiple-proc-transpose-in-one-macro/m-p/625425#M184324</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro pull(report,ln,col);

data have;
length ln $25.;
input ln cnt cnt2;
datalines;
4544 2 1
4544 3 1
4544 4 1
4544 5 1
4465 10 1
4465 5 1
4475 1 0
4475 2 0
4475 3 1
;

proc sort data=have;
by ln;
run;

proc sql;
create table &amp;amp;report. as
select ln cnt cnt2
from have
;
quit;

proc transpose data=&amp;amp;report.;
by &amp;amp;ln.;
var cnt cnt2;
run;

data &amp;amp;report (rename=(COL1=&amp;amp;col));
set have2;
run;

%mend pull;

%pull(_4544,4544,Mth1);
%pull(_4465,4465,Mth2);
%pull(_4475,4475,Mth3);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;Is there a way to have 3 different datasets handled in 1 macro separated by the ln and label the col1 in the proc transpose without 3 different datasets??&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Feb 2020 08:47:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Handle-multiple-proc-transpose-in-one-macro/m-p/625425#M184324</guid>
      <dc:creator>Q1983</dc:creator>
      <dc:date>2020-02-18T08:47:57Z</dc:date>
    </item>
    <item>
      <title>Re: Handle multiple proc transpose in one macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Handle-multiple-proc-transpose-in-one-macro/m-p/625432#M184331</link>
      <description>Hi,&lt;BR /&gt;  Are you sure your underlying code is working? The variables in the SELECT statement should be separated by commas so I would expect you to get an error message. and the value of &amp;amp;ln is number, like 4544, 4465 and 4475, so the BY statement in the PROC TRANSPOSE should be giving you errors too. Did you test out your code to see that it was working for 1 group before you made your Macro program?&lt;BR /&gt;Cynthia</description>
      <pubDate>Mon, 17 Feb 2020 20:27:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Handle-multiple-proc-transpose-in-one-macro/m-p/625432#M184331</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2020-02-17T20:27:29Z</dc:date>
    </item>
    <item>
      <title>Re: Handle multiple proc transpose in one macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Handle-multiple-proc-transpose-in-one-macro/m-p/625544#M184382</link>
      <description>&lt;P&gt;&lt;FONT size="4"&gt;&lt;STRONG&gt;PLEASE&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;do us (and yourself) a BIG favor by using the proper subwindow for posting code. I edited your post, so that the code is properly formatted and can easily be copy/pasted and submitted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Maxim 2: Read the Log!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;datalines are not allowed in a macro, so you have the first problem there.&lt;/P&gt;
&lt;P&gt;So I pulled the data step for "have" out of the macro, and ran the code again:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
length ln $25.;
input ln cnt cnt2;
datalines;
4544 2 1
4544 3 1
4544 4 1
4544 5 1
4465 10 1
4465 5 1
4475 1 0
4475 2 0
4475 3 1
;

%macro pull(report,ln,col);

proc sort data=have;
by ln;
run;

proc sql;
create table &amp;amp;report. as
select ln cnt cnt2
from have
;
quit;

proc transpose data=&amp;amp;report.;
by &amp;amp;ln.;
var cnt cnt2;
run;

data &amp;amp;report (rename=(COL1=&amp;amp;col));
set have2;
run;

%mend pull;

%pull(_4544,4544,Mth1)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which ended with a bunch of ERROR messages, so I went back to Rule #1 for macro development: START WITH WORKING CODE!&lt;/P&gt;
&lt;P&gt;I replaced the macro call with manually setting the parameters, and ran the code without the macro wrapped around it:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let report=_4544;
%let ln=4544;
%let col=Mth1;

proc sort data=have;
by ln;
run;

proc sql;
create table &amp;amp;report. as
select ln cnt cnt2
from have
;
quit;

proc transpose data=&amp;amp;report.;
by &amp;amp;ln.;
var cnt cnt2;
run;

data &amp;amp;report (rename=(COL1=&amp;amp;col));
set have2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Syntax ERROR in SQL:&lt;/P&gt;
&lt;PRE&gt;35         proc sql;
36         create table &amp;amp;report. as
37         select ln cnt cnt2
                     ___
                     22
                     202
ERROR 22-322: Syntaxfehler, erwartet wird eines der folgenden: eine Zeichenkette in Hochkommata, !, !!, &amp;amp;, (, *, **, +, ',', -, 
              '.', /, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;=, ?, AND, AS, BETWEEN, CONTAINS, EQ, EQT, FORMAT, FROM, GE, GET, GT, GTT, IN, INFORMAT, 
              INTO, IS, LABEL, LE, LEN, LENGTH, LET, LIKE, LT, LTT, NE, NET, NOT, NOTIN, OR, TRANSCODE, ^, ^=, |, ||, ~, ~=.  
&lt;/PRE&gt;
&lt;P&gt;Oh yes, we need commas here, so fix that:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table &amp;amp;report. as
select ln, cnt, cnt2
from have
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But now we get this:&lt;/P&gt;
&lt;PRE&gt;58         proc transpose data=&amp;amp;report.;
59         by &amp;amp;ln.;
NOTE: Line generated by the macro variable "LN".
59          4544
            ____
            22
            200
ERROR 22-322: Syntaxfehler, erwartet wird eines der folgenden: ein Name, ;, DESCENDING, NOTSORTED, _ALL_, _CHARACTER_, _CHAR_, 
              _NUMERIC_.  
&lt;/PRE&gt;
&lt;P&gt;Since you initially sorted by dataset variable ln (and not a macro variable!), let's correct that:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=&amp;amp;report.;
by ln;
var cnt cnt2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and now we only get&lt;/P&gt;
&lt;PRE&gt;63         data &amp;amp;report (rename=(COL1=&amp;amp;col));
64         set have2;
ERROR: Datei WORK.HAVE2.DATA existiert nicht.
&lt;/PRE&gt;
&lt;P&gt;Well, yes, there is no step that creates have2. And since you only do a rename here, you can do that immediately in the transpose.&lt;/P&gt;
&lt;P&gt;Let's do this, and use the dataset names in the proper order:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let report=_4544;
%let ln=4544;
%let col=Mth1;

proc sort data=have;
by ln;
run;

proc sql;
create table have2 as
select ln, cnt, cnt2
from have
;
quit;

proc transpose data=have2 out=&amp;amp;report. (rename=(COL1=&amp;amp;col));
by ln;
var cnt cnt2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;so now there's no ERRORS or WARNINGS, but I guess you expect another result, not this:&lt;/P&gt;
&lt;PRE&gt; ln     _NAME_    Mth1    COL2    COL3    COL4

4465     cnt       10       5       .       . 
4465     cnt2       1       1       .       . 
4475     cnt        1       2       3       . 
4475     cnt2       0       0       1       . 
4544     cnt        2       3       4       5 
4544     cnt2       1       1       1       1 
&lt;/PRE&gt;
&lt;P&gt;What do you expect for the first execution of your macro?&lt;/P&gt;</description>
      <pubDate>Tue, 18 Feb 2020 09:03:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Handle-multiple-proc-transpose-in-one-macro/m-p/625544#M184382</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-02-18T09:03:35Z</dc:date>
    </item>
  </channel>
</rss>

