<?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: Use the value of a variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Use-the-value-of-a-variable/m-p/29555#M5582</link>
    <description>Hi.&lt;BR /&gt;
It spend some time to understand your post.&lt;BR /&gt;
I am also not quit clarify.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
If you want different order of ORDER1 and ORDER2 for different Code.&lt;BR /&gt;
&lt;BR /&gt;
You can split your data into two datasets (each only contains A or B),then to order them &lt;BR /&gt;
separately. at the end to concatenate these two datasets vertically.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
    <pubDate>Wed, 16 Mar 2011 03:32:20 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2011-03-16T03:32:20Z</dc:date>
    <item>
      <title>Use the value of a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-the-value-of-a-variable/m-p/29551#M5578</link>
      <description>Hi !&lt;BR /&gt;
&lt;BR /&gt;
I have a table which has one column , say order1. I want to use the value in order1 to actually order my sas dataset. Say if order1 = id, then i want to order my sas datset by id. How can we acheive this?&lt;BR /&gt;
&lt;BR /&gt;
Thanks!!</description>
      <pubDate>Tue, 15 Mar 2011 01:36:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-the-value-of-a-variable/m-p/29551#M5578</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2011-03-15T01:36:17Z</dc:date>
    </item>
    <item>
      <title>Re: Use the value of a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-the-value-of-a-variable/m-p/29552#M5579</link>
      <description>Hi.&lt;BR /&gt;
I think you maybe can use proc compare or data step's merge statement to get it.&lt;BR /&gt;
And this maybe to code a macro.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Tue, 15 Mar 2011 06:59:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-the-value-of-a-variable/m-p/29552#M5579</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-03-15T06:59:29Z</dc:date>
    </item>
    <item>
      <title>Re: Use the value of a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-the-value-of-a-variable/m-p/29553#M5580</link>
      <description>This is my code where I first pull the data usin PROC SQL. &lt;BR /&gt;
select c.* ......, order1, order2 &lt;BR /&gt;
	from  table1 a&lt;BR /&gt;
	join  table 2  b&lt;BR /&gt;
	on a.id=b.id&lt;BR /&gt;
	join  table3 c&lt;BR /&gt;
	on b.cd= c.cd&lt;BR /&gt;
&lt;BR /&gt;
PROC SORT DATA=s_tmp OUT= s_sort nodupkey;&lt;BR /&gt;
  BY id , cd  ;&lt;BR /&gt;
RUN ;&lt;BR /&gt;
And my data looks like this: &lt;BR /&gt;
ID  Code  seq_no1  seq_no2  Order1   Order2&lt;BR /&gt;
1    A                                  seq_no1  seq_no2 &lt;BR /&gt;
1    A                                  seq_no1  seq_no2&lt;BR /&gt;
1    B</description>
      <pubDate>Tue, 15 Mar 2011 15:18:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-the-value-of-a-variable/m-p/29553#M5580</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2011-03-15T15:18:45Z</dc:date>
    </item>
    <item>
      <title>Re: Use the value of a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-the-value-of-a-variable/m-p/29554#M5581</link>
      <description>This is my code where I first pull the data usin PROC SQL. &lt;BR /&gt;
select c.* ......, order1, order2 &lt;BR /&gt;
	from  table1 a&lt;BR /&gt;
	join  table 2  b&lt;BR /&gt;
	on a.id=b.id&lt;BR /&gt;
	join  table3 c&lt;BR /&gt;
	on b.cd= c.cd&lt;BR /&gt;
&lt;BR /&gt;
PROC SORT DATA=s_tmp OUT= s_sort nodupkey;&lt;BR /&gt;
  BY id , cd  ;&lt;BR /&gt;
RUN ;&lt;BR /&gt;
And my data looks like this: &lt;BR /&gt;
ID  Code  seq_no1  seq_no2     Order1        Order2&lt;BR /&gt;
1    A              1      1              seq_no1    seq_no2 &lt;BR /&gt;
1    A              2      2             seq_no1     seq_no2&lt;BR /&gt;
1    B              2      2            seq_no2      seq_no1&lt;BR /&gt;
1    B               1     1           seq_no2        seq_no1&lt;BR /&gt;
&lt;BR /&gt;
So now within an ID , I have different codes, so I want to first order by Code(eg A,B) and then Order by the values in column Order1 and Order2. &lt;BR /&gt;
So Order1 has Seq_no1 for Code A, so within Code A , I would like to order by Seq_no1 and then by Seq_no2. However within code B, first I need ot order by Seq_no2 and then by seq_no1. &lt;BR /&gt;
&lt;BR /&gt;
So a simple 'order by Order1' will not work here. Can u  help me with using proc compare of a merge here?</description>
      <pubDate>Tue, 15 Mar 2011 15:24:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-the-value-of-a-variable/m-p/29554#M5581</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2011-03-15T15:24:27Z</dc:date>
    </item>
    <item>
      <title>Re: Use the value of a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-the-value-of-a-variable/m-p/29555#M5582</link>
      <description>Hi.&lt;BR /&gt;
It spend some time to understand your post.&lt;BR /&gt;
I am also not quit clarify.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
If you want different order of ORDER1 and ORDER2 for different Code.&lt;BR /&gt;
&lt;BR /&gt;
You can split your data into two datasets (each only contains A or B),then to order them &lt;BR /&gt;
separately. at the end to concatenate these two datasets vertically.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Wed, 16 Mar 2011 03:32:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-the-value-of-a-variable/m-p/29555#M5582</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-03-16T03:32:20Z</dc:date>
    </item>
    <item>
      <title>Re: Use the value of a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-the-value-of-a-variable/m-p/29556#M5583</link>
      <description>My bad . Let me explain again.Changed the example to make it less confusing.&lt;BR /&gt;
ID Code seq_no1   Order1               Order2           First Name    LAst Name&lt;BR /&gt;
1   A       1            seq_no1                                   &lt;BR /&gt;
1   A       2            seq_no1 &lt;BR /&gt;
1   B       2            FirstName           Last name      John           Well &lt;BR /&gt;
1   B       1            First NAme          Last name      Aaron         Hancock &lt;BR /&gt;
&lt;BR /&gt;
Since Order1=Seq_no1, all the observations with Code=A, should be ordered by seq_no_1.So this input data is alreayd sorted. Now since, Order1= First name , and Order2 = Last name, All the observations under Code=B should be first sorted on First names and then on last names. So irrespective of seq_no , all obs under cod=b should be sorted by NAmes. &lt;BR /&gt;
&lt;BR /&gt;
If I use code as below it will not work .&lt;BR /&gt;
Sel * from table...&lt;BR /&gt;
order by Order1&lt;BR /&gt;
&lt;BR /&gt;
I am trying to use a dynamic Order by clause But I am getting an error. Other than changing the data type, is there a way around this? &lt;BR /&gt;
 order by c.id, a.code,&lt;BR /&gt;
  case when &amp;amp;ord1_by = 'SEQ_NO' then SEQ_NO&lt;BR /&gt;
      when &amp;amp;ord1_by = 'PD' then PD&lt;BR /&gt;
         end ;&lt;BR /&gt;
ERROR: Expression using equals (=) has components that are of different data types.&lt;BR /&gt;
ERROR: Expression using equals (=) has components that are of different data types.&lt;BR /&gt;
ERROR: Result of WHEN clause 2 is not the same data type as the preceding results.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Thanks!

Message was edited by: sasnewbee</description>
      <pubDate>Wed, 16 Mar 2011 14:03:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-the-value-of-a-variable/m-p/29556#M5583</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2011-03-16T14:03:20Z</dc:date>
    </item>
    <item>
      <title>Re: Use the value of a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-the-value-of-a-variable/m-p/29557#M5584</link>
      <description>Hi.&lt;BR /&gt;
You can make a new variable for order.&lt;BR /&gt;
Such as :&lt;BR /&gt;
if seq_no1 =seq_no1 then order=seq_no1;&lt;BR /&gt;
 else if seq_no2=seq_no2 then order=seq_no2&lt;BR /&gt;
....................................&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Thu, 17 Mar 2011 04:12:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-the-value-of-a-variable/m-p/29557#M5584</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-03-17T04:12:10Z</dc:date>
    </item>
    <item>
      <title>Re: Use the value of a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-the-value-of-a-variable/m-p/29558#M5585</link>
      <description>Hi:&lt;BR /&gt;
  Without seeing more of your data, I am wondering whether you are misunderstanding the data fields. For example, it seems sort of odd to me that seq_no1 for Firstname=Aaron is 1 and seq_no1 for Firstname=John is 2. That makes me wonder whether all you have to do is:&lt;BR /&gt;
[pre]&lt;BR /&gt;
proc sort data=mydata out=sortdata;&lt;BR /&gt;
  by code seq_no1;&lt;BR /&gt;
run;&lt;BR /&gt;
      &lt;BR /&gt;
OR&lt;BR /&gt;
        &lt;BR /&gt;
proc sort data=mydata out=sortdata;&lt;BR /&gt;
  by id code seq_no1;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
   &lt;BR /&gt;
Perhaps the original data is telling you the order that the data was INTENDED to be in and if you sort by CODE and SEQ_NO1 or ID, CODE and SEQ_NO1, you will get the intended order. For the small data sample that you've posted, if you merely sorted by CODE and SEQ_NO1, your "B" codes would sort correctly.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Thu, 17 Mar 2011 16:29:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-the-value-of-a-variable/m-p/29558#M5585</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2011-03-17T16:29:16Z</dc:date>
    </item>
  </channel>
</rss>

