<?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: Write non-existent variables in a PROC TRANSPOSE statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Write-non-existent-variables-in-a-PROC-TRANSPOSE-statement/m-p/971603#M377365</link>
    <description>&lt;P&gt;You need to make a dummy dataset to include all these months and using MERGE skill to get job done.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
input id month $ amount;
cards;
1 month1 23
1 month1 12
1 month2 10
2 month1 90
2 month1 4
;




*Make a dummy MONTH dataset;
data month;
input month $;
cards;
month1
month2
month3
;
proc sql noprint;
select distinct catt('have(where=(month="',month,'") rename=(amount=',month,'))') into :merge separated by ' ' 
 from month;
quit;
data want;
 merge &amp;amp;merge.;
 by id;
 output;
 call missing(of _all_);
 drop month;
run;&lt;/PRE&gt;</description>
    <pubDate>Tue, 29 Jul 2025 09:13:08 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2025-07-29T09:13:08Z</dc:date>
    <item>
      <title>Write non-existent variables in a PROC TRANSPOSE statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Write-non-existent-variables-in-a-PROC-TRANSPOSE-statement/m-p/971602#M377364</link>
      <description>&lt;P&gt;Hi to the community! I am having the following issue. I am having a dataset of banking transactions by customer and month. However, currently (July 2025) there have been transactions only in month1 (April 2025). See below a simplified example:&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%"&gt;&lt;STRONG&gt;id&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;&lt;STRONG&gt;month&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;&lt;STRONG&gt;amount&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%"&gt;1&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;month1&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;23&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%"&gt;1&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;month1&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;12&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%"&gt;2&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;month1&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;90&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;month1&lt;/TD&gt;
&lt;TD&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to transpose using PROC TRANSPOSE as follows:&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="25%" height="30px"&gt;&lt;STRONG&gt;id&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;&lt;STRONG&gt;month1&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;&lt;STRONG&gt;month2&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;&lt;STRONG&gt;month3&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="25%" height="30px"&gt;1&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;23&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;.&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;.&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="25%" height="30px"&gt;1&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;12&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;.&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;.&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="25%" height="30px"&gt;2&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;90&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;.&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;.&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="25%" height="30px"&gt;2&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;4&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;.&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;.&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To do so, I am using the following PROC TRANSPOSE statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=amounts out=amounts_trans (keep=id month1 month2 month3);
  by id;
  var amount;
  id Month;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;However, because I do not have data (at least this month) for month2 and month3, this statement results in the following table:&lt;/P&gt;
&lt;TABLE border="1" width="126.5px"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="62.25px" height="30px"&gt;&lt;STRONG&gt;id&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="63.25px" height="30px"&gt;&lt;STRONG&gt;month1&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="62.25px" height="30px"&gt;1&lt;/TD&gt;
&lt;TD width="63.25px" height="30px"&gt;23&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="62.25px" height="30px"&gt;1&lt;/TD&gt;
&lt;TD width="63.25px" height="30px"&gt;12&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="62.25px" height="30px"&gt;2&lt;/TD&gt;
&lt;TD width="63.25px" height="30px"&gt;90&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="62.25px" height="30px"&gt;2&lt;/TD&gt;
&lt;TD width="63.25px" height="30px"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And it gives me those warnings:&lt;/P&gt;
&lt;DIV&gt;
&lt;DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;WARNING: The variable month2 in the DROP, KEEP, or RENAME list has never been referenced.&lt;/STRONG&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;WARNING: The variable month3 in the DROP, KEEP, or RENAME list has never been referenced.&lt;/STRONG&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;I need variables month2 and month3 in the transposed table, because they are referenced later in the script. Do you know how I can solve this issue? I could use DATA step and arrays instead of PROC TRANSPOSE, but I am not allowed, as I have to keep the code as original as possible.&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jul 2025 08:30:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Write-non-existent-variables-in-a-PROC-TRANSPOSE-statement/m-p/971602#M377364</guid>
      <dc:creator>mvalsamis</dc:creator>
      <dc:date>2025-07-29T08:30:11Z</dc:date>
    </item>
    <item>
      <title>Re: Write non-existent variables in a PROC TRANSPOSE statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Write-non-existent-variables-in-a-PROC-TRANSPOSE-statement/m-p/971603#M377365</link>
      <description>&lt;P&gt;You need to make a dummy dataset to include all these months and using MERGE skill to get job done.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
input id month $ amount;
cards;
1 month1 23
1 month1 12
1 month2 10
2 month1 90
2 month1 4
;




*Make a dummy MONTH dataset;
data month;
input month $;
cards;
month1
month2
month3
;
proc sql noprint;
select distinct catt('have(where=(month="',month,'") rename=(amount=',month,'))') into :merge separated by ' ' 
 from month;
quit;
data want;
 merge &amp;amp;merge.;
 by id;
 output;
 call missing(of _all_);
 drop month;
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Jul 2025 09:13:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Write-non-existent-variables-in-a-PROC-TRANSPOSE-statement/m-p/971603#M377365</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-07-29T09:13:08Z</dc:date>
    </item>
  </channel>
</rss>

