DATA Step, Macro, Functions and more

IDENTITY ou AUTOINCREMENT

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 5
Accepted Solution

IDENTITY ou AUTOINCREMENT

Prezados,

É possivel criar um campo auto numerado (IDENTITY) no SAS? Quais são as maneiras de fazer esse processo?

Ex:

CREATE TABLE exemplo

(

     COD_CLI INT IDENTITY,

     NOME VARCHAR(50),

     EMAIL VARCHAR(50)

CONSTRAINT EXEMPLO_PK_COD_CLI PRIMARY KEY(COD_CLI)

);

Obrigado pela atenção!


Accepted Solutions
Solution
‎03-08-2013 11:34 AM
PROC Star
Posts: 1,167

Re: IDENTITY ou AUTOINCREMENT

No, there is no identity option in SAS. Perhaps the undocumented monotonic() function could be useful

http://www.amadeus.co.uk/sas-technical-services/tips-and-techniques/sql/the-monotonic-function/.

View solution in original post


All Replies
Solution
‎03-08-2013 11:34 AM
PROC Star
Posts: 1,167

Re: IDENTITY ou AUTOINCREMENT

No, there is no identity option in SAS. Perhaps the undocumented monotonic() function could be useful

http://www.amadeus.co.uk/sas-technical-services/tips-and-techniques/sql/the-monotonic-function/.

Occasional Contributor
Posts: 5

Re: IDENTITY ou AUTOINCREMENT

TomKari, Boa Tarde!

Eu consegui, utilizei o exemplo que você passou.

Muito Obrigado!

PROC Star
Posts: 1,167

Re: IDENTITY ou AUTOINCREMENT

Seja bem-vindo!

Tom

Occasional Contributor
Posts: 5

Re: IDENTITY ou AUTOINCREMENT

Obrigado!

Super User
Posts: 10,023

Re: IDENTITY ou AUTOINCREMENT

I will not ust that undocumented function for the sake of risk. I would like use ODS.

ods listing close;

ods output sql_results=want;

proc sql number;

select * from sashelp.class;

quit;

ods listing;

Ksharp

Occasional Contributor
Posts: 5

Re: IDENTITY ou AUTOINCREMENT

Ksharp, Bom Dia!

Você tem um exemplo de como usar o código que você mostrou?

Ex:

PROC SQL;

     CREATE TABLE MINHA_TABELA AS

     SELECT * FROM TABELA_BASE;

RUN;

Super User
Posts: 10,023

Re: IDENTITY ou AUTOINCREMENT

Please English first . I have to go to sleep now. will be back soon after a beauty sleep.

Occasional Contributor
Posts: 5

Re: IDENTITY ou AUTOINCREMENT

Ksharp, Good Day!

Do you have an example of how to use the code you showed?

Ex:

PROC SQL;

     CREATE TABLE MINHA_TABELA AS

     SELECT * FROM TABELA_BASE;

RUN;

Respected Advisor
Posts: 4,920

Re: IDENTITY ou AUTOINCREMENT

Olá. Just follow what Ksharp wrote :

ods listing close;

ods output sql_results=MINHA_TABELA;

proc sql number;

     select * from TABELA_BASE;

quit;

ods listing;

The first statement prevents the printing of query results. The second statement directs the query result to dataset MINHA_TABELA. Option number adds a column in the query result to contain record numbers. The last statement restores normal result printing.

MINHA_TABELA will contain the same columns as TABELA_BASE with an extra column for record numbers.

PG

PG
Super User
Posts: 10,023

Re: IDENTITY ou AUTOINCREMENT

PG, Thanks. So detail explanation for me  .

Ksharp

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 10 replies
  • 821 views
  • 0 likes
  • 4 in conversation