<?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: automation code to create new datasets with transposed variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/automation-code-to-create-new-datasets-with-transposed-variables/m-p/972883#M377590</link>
    <description>&lt;P&gt;Still not clear. To write any code, I have to know the starting point, most likely a data set, and then the desired steps thereafter that produce the desired output. I think the desired output is clear, but where in all of these words you have written do I start?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you provide a sample data set that I can start from? Please provide the sample data set as working SAS data step code (&lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;examples and instructions&lt;/A&gt;), not as Excel files, not as copy and paste, only working SAS data step code is acceptable. Please provide an example list of variables.&lt;/P&gt;</description>
    <pubDate>Tue, 19 Aug 2025 14:34:36 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2025-08-19T14:34:36Z</dc:date>
    <item>
      <title>automation code to create new datasets with transposed variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/automation-code-to-create-new-datasets-with-transposed-variables/m-p/972869#M377585</link>
      <description>&lt;P&gt;Dear All&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;first of all I would like to thank in advance all of You who would help me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I usually perform my analyses after PS matching this way (I attach a sample code):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;proc means data=matchedunpaired mean std;
class group;
var cont1;
title 'cont1';
run;

DATA mcont1;
	SET pairedcontinuous;
	WHERE Variables='cont1';
RUN;

PROC TTEST data= mcont1;
	PAIRED _0*_1 ;
RUN;&lt;/PRE&gt;&lt;PRE&gt;title 'Cat1';

proc freq data=matchedunpaired;
	table cat1*group/nopercent nocum norow;
run;

DATA mcat1;
	SET pairedcategorical;
	WHERE Variables='cat1';
RUN;

PROC FREQ data=mcat1 ;
	TABLE _0*_1;
	EXACT mcnem;
RUN;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to build a macro (or some sort of automation) which might help me in creating new datasets (and consequentially performing new procedures) from a list of variables, without doing it manually.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Would it be possible?&lt;/P&gt;&lt;P&gt;Sincerely&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Antonio&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Aug 2025 11:06:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/automation-code-to-create-new-datasets-with-transposed-variables/m-p/972869#M377585</guid>
      <dc:creator>antor82</dc:creator>
      <dc:date>2025-08-19T11:06:27Z</dc:date>
    </item>
    <item>
      <title>Re: automation code to create new datasets with transposed variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/automation-code-to-create-new-datasets-with-transposed-variables/m-p/972872#M377587</link>
      <description>&lt;P&gt;I'm sorry but this is far too vague for me to offer any assistance. Please be much more specific. Where would the new variables be used? What new data sets do you want? What list of variables are you referring to?&lt;/P&gt;</description>
      <pubDate>Tue, 19 Aug 2025 11:30:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/automation-code-to-create-new-datasets-with-transposed-variables/m-p/972872#M377587</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-08-19T11:30:00Z</dc:date>
    </item>
    <item>
      <title>Re: automation code to create new datasets with transposed variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/automation-code-to-create-new-datasets-with-transposed-variables/m-p/972881#M377589</link>
      <description>Dear PaigeMiller&lt;BR /&gt;&lt;BR /&gt;Thank you for your prompt reply.&lt;BR /&gt;&lt;BR /&gt;I’ve an original dataset which I used for unmatched analyses. Then I’ve performed my PS matching procedure and I’ve obtained an output with all 1:1 matched cases.&lt;BR /&gt;&lt;BR /&gt;I’ve transposed all the data into two different datasets (one for continuous variables, one for categorical ones) and performed my paired analyses following the steps described into the online guide (&lt;A href="https://documentation.sas.com/doc/en/statug/15.2/statug_psmatch_examples09.htm" target="_blank"&gt;https://documentation.sas.com/doc/en/statug/15.2/statug_psmatch_examples09.htm&lt;/A&gt;).&lt;BR /&gt;&lt;BR /&gt;My question is: should I repeat manually all these steps for each single variable or is there some syntax that might do this for me (obviously specifying the list of variables to be included)?&lt;BR /&gt;&lt;BR /&gt;Thanks in advance&lt;BR /&gt;&lt;BR /&gt;Antonio&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 19 Aug 2025 14:14:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/automation-code-to-create-new-datasets-with-transposed-variables/m-p/972881#M377589</guid>
      <dc:creator>antor82</dc:creator>
      <dc:date>2025-08-19T14:14:02Z</dc:date>
    </item>
    <item>
      <title>Re: automation code to create new datasets with transposed variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/automation-code-to-create-new-datasets-with-transposed-variables/m-p/972883#M377590</link>
      <description>&lt;P&gt;Still not clear. To write any code, I have to know the starting point, most likely a data set, and then the desired steps thereafter that produce the desired output. I think the desired output is clear, but where in all of these words you have written do I start?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you provide a sample data set that I can start from? Please provide the sample data set as working SAS data step code (&lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;examples and instructions&lt;/A&gt;), not as Excel files, not as copy and paste, only working SAS data step code is acceptable. Please provide an example list of variables.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Aug 2025 14:34:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/automation-code-to-create-new-datasets-with-transposed-variables/m-p/972883#M377590</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-08-19T14:34:36Z</dc:date>
    </item>
    <item>
      <title>Re: automation code to create new datasets with transposed variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/automation-code-to-create-new-datasets-with-transposed-variables/m-p/972884#M377591</link>
      <description>&lt;P&gt;So that page is using datasets defined in other pages and has a lot of steps.&amp;nbsp; Please share a simple example dataset and the steps you are currently using to process it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can probably do it without having to perform code generation (aka making a macro).&amp;nbsp; Instead you could probably just use BY group processing.&amp;nbsp;&amp;nbsp;If you have keys that uniquely identify the observations in your original dataset then PROC TRANSPOSE will convert multiple variables into multiple observations with the a variable indicating which observations came from which variable.&amp;nbsp; &amp;nbsp;So something like this will convert a wide dataset into a tall dataset.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=have out=tall(rename=(col1=value)) name=variable;
  by key1 key2 ;
  var var1 var2 var3 ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can then sort it by the name variable and then do your later steps BY that variable.&amp;nbsp; So for example if your first proc step was PROC MEANS it might look like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=tall;
  by variable key1 key2;
run;
proc means data=tall;
  by variable;
  var value;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 19 Aug 2025 14:38:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/automation-code-to-create-new-datasets-with-transposed-variables/m-p/972884#M377591</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-08-19T14:38:41Z</dc:date>
    </item>
    <item>
      <title>Re: automation code to create new datasets with transposed variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/automation-code-to-create-new-datasets-with-transposed-variables/m-p/972932#M377600</link>
      <description>&lt;P&gt;You could faster your code via BY statement.&lt;/P&gt;
&lt;P&gt;For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;DATA mcont1;
	SET pairedcontinuous;
	WHERE Variables='cont1';
RUN;

&lt;STRONG&gt;proc sort data=mcont1;
by Variables;
run;&lt;BR /&gt;/*ODS OUTPUT .....  &amp;lt;---this could save the output as a dataset*/&lt;/STRONG&gt;
PROC TTEST data= mcont1;
&lt;STRONG&gt;by Variables;&lt;/STRONG&gt;
	PAIRED _0*_1 ;
RUN;&lt;/PRE&gt;
&lt;PRE&gt;DATA mcat1;
	SET pairedcategorical;
	WHERE Variables='cat1';
RUN;

&lt;STRONG&gt;proc sort data=mcat1;
by Variables;
run;&lt;BR /&gt;/*ODS OUTPUT ..... &amp;lt;---this could save the output as a dataset*/&lt;/STRONG&gt;
PROC FREQ data=mcat1 ;
&lt;STRONG&gt;by Variables;&lt;/STRONG&gt;
	TABLE _0*_1;
	EXACT mcnem;
RUN;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Aug 2025 01:25:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/automation-code-to-create-new-datasets-with-transposed-variables/m-p/972932#M377600</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-08-20T01:25:30Z</dc:date>
    </item>
    <item>
      <title>Re: automation code to create new datasets with transposed variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/automation-code-to-create-new-datasets-with-transposed-variables/m-p/972940#M377604</link>
      <description>&lt;P&gt;Thank you very much! this was exactly what I needed!!!&lt;/P&gt;</description>
      <pubDate>Wed, 20 Aug 2025 06:25:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/automation-code-to-create-new-datasets-with-transposed-variables/m-p/972940#M377604</guid>
      <dc:creator>antor82</dc:creator>
      <dc:date>2025-08-20T06:25:42Z</dc:date>
    </item>
  </channel>
</rss>

