<?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: Duplicate dataset, create a variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Duplicate-dataset-create-a-variable/m-p/777127#M247197</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/5599"&gt;@foxrol94&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a dataset ONE and want to :&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Duplicate ONE dataset&lt;/LI&gt;
&lt;LI&gt;Each row is now doubled. So for each pair I will want to create a new variable &lt;STRONG&gt;top&lt;/STRONG&gt; which is 'x' on the first row and nothing on the second.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;The code below only gives me the character 'x' on the second line when I would like it on the first&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data TMP_ONE;
	set ONE;
	top = 'x';
	run;

data TMP_1_ONE;
	set ONE;
	top = '';
	run;
data I_ONE;
set TMP_ONE TMP_1_ONE;
run;

proc sort data=I_ONE out=I_TWO;
by _all_  top;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Your sort says to sort by the order of TOP. Blank comes before 'X'. If you want the 'X' first, assuming no other value of Top is 'larger' or would come after X alphabetically then&lt;/P&gt;
&lt;PRE&gt;proc sort data=I_ONE out=I_TWO;
   by _all_  &lt;FONT color="#800080"&gt;&lt;STRONG&gt;descending&lt;/STRONG&gt;&lt;/FONT&gt; top;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 28 Oct 2021 21:39:10 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2021-10-28T21:39:10Z</dc:date>
    <item>
      <title>Duplicate dataset, create a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Duplicate-dataset-create-a-variable/m-p/776969#M247120</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a dataset ONE and want to :&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Duplicate ONE dataset&lt;/LI&gt;
&lt;LI&gt;Each row is now doubled. So for each pair I will want to create a new variable &lt;STRONG&gt;top&lt;/STRONG&gt; which is 'x' on the first row and nothing on the second.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;The code below only gives me the character 'x' on the second line when I would like it on the first&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data TMP_ONE;
	set ONE;
	top = 'x';
	run;

data TMP_1_ONE;
	set ONE;
	top = '';
	run;
data I_ONE;
set TMP_ONE TMP_1_ONE;
run;

proc sort data=I_ONE out=I_TWO;
by _all_  top;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Oct 2021 13:49:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Duplicate-dataset-create-a-variable/m-p/776969#M247120</guid>
      <dc:creator>foxrol94</dc:creator>
      <dc:date>2021-10-28T13:49:55Z</dc:date>
    </item>
    <item>
      <title>Re: Duplicate dataset, create a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Duplicate-dataset-create-a-variable/m-p/776973#M247122</link>
      <description>&lt;P&gt;I think this does what you want, all in one DATA step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set ONE;
    top = 'x';
    output;
    top = ' ';
    output;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 Oct 2021 14:21:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Duplicate-dataset-create-a-variable/m-p/776973#M247122</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-10-28T14:21:50Z</dc:date>
    </item>
    <item>
      <title>Re: Duplicate dataset, create a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Duplicate-dataset-create-a-variable/m-p/777127#M247197</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/5599"&gt;@foxrol94&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a dataset ONE and want to :&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Duplicate ONE dataset&lt;/LI&gt;
&lt;LI&gt;Each row is now doubled. So for each pair I will want to create a new variable &lt;STRONG&gt;top&lt;/STRONG&gt; which is 'x' on the first row and nothing on the second.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;The code below only gives me the character 'x' on the second line when I would like it on the first&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data TMP_ONE;
	set ONE;
	top = 'x';
	run;

data TMP_1_ONE;
	set ONE;
	top = '';
	run;
data I_ONE;
set TMP_ONE TMP_1_ONE;
run;

proc sort data=I_ONE out=I_TWO;
by _all_  top;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Your sort says to sort by the order of TOP. Blank comes before 'X'. If you want the 'X' first, assuming no other value of Top is 'larger' or would come after X alphabetically then&lt;/P&gt;
&lt;PRE&gt;proc sort data=I_ONE out=I_TWO;
   by _all_  &lt;FONT color="#800080"&gt;&lt;STRONG&gt;descending&lt;/STRONG&gt;&lt;/FONT&gt; top;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Oct 2021 21:39:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Duplicate-dataset-create-a-variable/m-p/777127#M247197</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-10-28T21:39:10Z</dc:date>
    </item>
    <item>
      <title>Re: Duplicate dataset, create a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Duplicate-dataset-create-a-variable/m-p/777235#M247240</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;this doesn't work for me.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data TMP_ONE;
	set sashelp.class;
	top = 'x';
	run;

data TMP_1_ONE;
	set  sashelp.class;
	top = ' ';
	run;
data I_ONE;
set TMP_ONE TMP_1_ONE;
run;

proc sort data=I_ONE out=I_TWO;
   by _all_  descending top;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;does not produce the requested ordering because (I think) the BY statement in PROC SORT is now really&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;by name sex age height weight top descending top;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;so first TOP is sorted ascending and then within that TOP is sorted descending, and the first sort of TOP in ascending order "overpowers" the second sort of TOP in descending order.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Oct 2021 10:57:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Duplicate-dataset-create-a-variable/m-p/777235#M247240</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-10-29T10:57:03Z</dc:date>
    </item>
    <item>
      <title>Re: Duplicate dataset, create a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Duplicate-dataset-create-a-variable/m-p/777308#M247266</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;this doesn't work for me.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data TMP_ONE;
	set sashelp.class;
	top = 'x';
	run;

data TMP_1_ONE;
	set  sashelp.class;
	top = ' ';
	run;
data I_ONE;
set TMP_ONE TMP_1_ONE;
run;

proc sort data=I_ONE out=I_TWO;
   by _all_  descending top;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;does not produce the requested ordering because (I think) the BY statement in PROC SORT is now really&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;by name sex age height weight top descending top;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;so first TOP is sorted ascending and then within that TOP is sorted descending, and the first sort of TOP in ascending order "overpowers" the second sort of TOP in descending order.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Right. I never use _all_ for sort so forgot the variable Top would in effect be on the By twice.&lt;/P&gt;
&lt;P&gt;But perhaps the OP can actually list the variables that are &lt;STRONG&gt;needed&lt;/STRONG&gt; for the sort by name and have the variable in correct position in the BY statements.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Oct 2021 14:35:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Duplicate-dataset-create-a-variable/m-p/777308#M247266</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-10-29T14:35:27Z</dc:date>
    </item>
  </channel>
</rss>

