<?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: Melting a dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Melting-a-dataset/m-p/557434#M155398</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA WORK.dat1;
  INPUT      A B C;
   datalines;
0 0 0
0 2 0
0 0 0
0 1 0
1 0 2
1 2 1
1 1 1
1 1 1
;
proc print;
   run;
proc transpose out=test name=colnames;
   run;
proc transpose out=test(rename=col1=values drop=_:);
   by colnames notsorted;
   run;
proc print;
   run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 151px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/29352i0EB5D806FE590B1D/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 09 May 2019 13:32:05 GMT</pubDate>
    <dc:creator>data_null__</dc:creator>
    <dc:date>2019-05-09T13:32:05Z</dc:date>
    <item>
      <title>Melting a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Melting-a-dataset/m-p/557410#M155393</link>
      <description>&lt;P&gt;As a matter of an example I have the following dataset and I want what is shown in the right side of the arrow:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="MeltDataset.PNG" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/29347i6E80D449C1B8101E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="MeltDataset.PNG" alt="MeltDataset.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;My idea was to&amp;nbsp;&lt;/P&gt;&lt;P&gt;(1) make a macro to&amp;nbsp;select the colnames of whatever dataset table and put it into an array;&lt;/P&gt;&lt;P&gt;(2) make a macro that you input a column and returns two columns (one with the colname and the other with the values)&amp;nbsp;&lt;/P&gt;&lt;P&gt;(3) make a macro that concatenates / merges two datasets into another.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then iterably getting the result.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am having troubles even to get the names of a table so I really kindly ask for help.&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;Condition: Can't used proc iml or R language.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here I put the dataCode&lt;/P&gt;&lt;PRE&gt;DATA WORK.dat1;
  INPUT      A B C;
   datalines;
0 0 0
0 2 0
0 0 0
0 1 0
1 0 2
1 2 1
1 1 1
1 1 1
;&lt;/PRE&gt;&lt;P&gt;Can someone help me in the writing of the code for the macros ? No need for the iteration part since I can do it&lt;/P&gt;&lt;P&gt;Thank you in advance for so much help,&lt;/P&gt;</description>
      <pubDate>Thu, 09 May 2019 12:00:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Melting-a-dataset/m-p/557410#M155393</guid>
      <dc:creator>carles</dc:creator>
      <dc:date>2019-05-09T12:00:17Z</dc:date>
    </item>
    <item>
      <title>Re: Melting a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Melting-a-dataset/m-p/557413#M155394</link>
      <description>&lt;P&gt;Let me point out that there is no need for macros here, re-arranging your data set can almost always be performed with data step operations, and/or PROC TRANSPOSE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This gives the result you want, you will need to sort data set WANT to your final required condition.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set dat1;
	colnames='A';
	value=a;
	output;
	colnames='B';
	value=b;
	output;
	colnames='C';
	value=c;
	output;
	keep colnames value;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 May 2019 12:03:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Melting-a-dataset/m-p/557413#M155394</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-05-09T12:03:16Z</dc:date>
    </item>
    <item>
      <title>Re: Melting a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Melting-a-dataset/m-p/557414#M155395</link>
      <description>&lt;P&gt;I'm not sure I would want to complicate this by adding macro language.&amp;nbsp; How about:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set have;
   array nums {*} _numeric_;
   do _n_=1 to dim(nums);
      colnames = vname(nums{_n_});
      values = nums{_n_};
      output;
   end;&lt;BR /&gt;   keep colnames values;
run;

proc sort data=want;
   by colnames;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This processes numeric variables only, but you would need to process character variables separately.&amp;nbsp; You could not use a single variable (VALUES) to hold both numeric and character values.&lt;/P&gt;</description>
      <pubDate>Thu, 09 May 2019 12:04:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Melting-a-dataset/m-p/557414#M155395</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-05-09T12:04:15Z</dc:date>
    </item>
    <item>
      <title>Re: Melting a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Melting-a-dataset/m-p/557434#M155398</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA WORK.dat1;
  INPUT      A B C;
   datalines;
0 0 0
0 2 0
0 0 0
0 1 0
1 0 2
1 2 1
1 1 1
1 1 1
;
proc print;
   run;
proc transpose out=test name=colnames;
   run;
proc transpose out=test(rename=col1=values drop=_:);
   by colnames notsorted;
   run;
proc print;
   run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 151px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/29352i0EB5D806FE590B1D/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 May 2019 13:32:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Melting-a-dataset/m-p/557434#M155398</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2019-05-09T13:32:05Z</dc:date>
    </item>
    <item>
      <title>Re: Melting a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Melting-a-dataset/m-p/557714#M155524</link>
      <description>&lt;P&gt;Thank you so much for the answer, this indeed works as well as the other I have accepted as answer.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Nevertheless, I could only give one accepted answer, but thank you for the time spent in the question&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 May 2019 09:11:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Melting-a-dataset/m-p/557714#M155524</guid>
      <dc:creator>carles</dc:creator>
      <dc:date>2019-05-10T09:11:52Z</dc:date>
    </item>
  </channel>
</rss>

