Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create unique identifier / create new primary variable 2

Status
Not open for further replies.

DonaZ

Technical User
Oct 10, 2007
41
0
0
US
Hi,

I created a table to rank the TOP 10 var1.
Now I want to create a new primary variable for the Top 10 var1. Ideally I want to use the same numbering as seen in the SAS view table. Can you help?

Thank you for your time.

DonaZ
 
Could you restate your question in a different way?

I'm not sure I follow what you're trying to do.
 
Sample of the SAS view table, I ranked the following:

obs fruits response
1 apples 100
2 peaches 90
3 pears 90
4 grapes 85
5 nectarines 80
6 watermelon 80
7 catalope 75
8 strawberries60
9 managoes 60
10 bananas 50

I want to create another variable like a primary key(or obs as seem in the SAS view table). When I link this table with another table, the information will be in the same numeric (obs) order. This is the only way that I can have the same consistent order I cannot alpa order since strawberries and managoes are both 60--M comes before S.

 
Hi Dona,

If I understood your question correctly, you wanted to create a variable that is the same as obs. Here are two different ways to do this.

Creating your data:

Code:
data have;
   input  fruits :$13. response;
   cards;
apples      100
peaches      90
pears        90
grapes       85
nectarines   80
watermelon   80
catalope     75
strawberries 60
managoes     60
bananas      50
   ;run;

In the datastep we can use the automatic variable _n_ that contains the number of the current record

Code:
data want1;
   set have;
   obs =_n_;
   run;

To do the same in SQL we can use the monotonic function

Code:
proc sql;
   create table want2 as
   select monotonic() as obs, * 
   from have;
   quit;

HTH
 
Thank you very much. This is exactly what I wanted.
 
kdt82 - Awesome, I had no idea how to do this in Proc SQL. :)

Chris
Business Analyst, Code Monkey, Data Wrangler.
SAS Guru.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top