BookmarkSubscribeRSS Feed
buckeye
Obsidian | Level 7
Hi all,

With Number specified in proc sql as an option shown below, but I couldn't get it in the subsequent data file mytable.

Is the ROW just for the printing purpose and we can not use it as a field or column? Thanks in advance.

data tbl;
input first $1. second third fourth ;
datalines
;
a 21 22 23
s 31 32 33
d 41 42 43
f 51 52 53
;
run
;
proc sql number ;
create table mytbl as
select * from tbl;
/* select statements */
select * from mytbl;
select 'r' || row as myrownumber, * from mytbl;
quit;
6 REPLIES 6
SPR
Quartz | Level 8 SPR
Quartz | Level 8
Hello Buckeye,

If you would like to number your rows like r1, r2, r3, etc. then it could be done like this:
[pre]
proc SQL;
create table mytbl as
select CATS("r",put(MONOTONIC(),6.)) as myrownumber, * from tbl;
quit;
proc print data=mytbl noobs;
run;
[/pre]
Sincerely,
SPR
buckeye
Obsidian | Level 7
That is exactly what I need. Thanks a lot.
Cynthia_sas
SAS Super FREQ
Hi:
It is up to you whether to use MONOTONIC() or not. However, you should be aware of this Tech Support note:
http://support.sas.com/kb/15/138.html

cynthia
darrylovia
Quartz | Level 8
I've used the MONOTINC function with no ill effects for one table processing. I believe when joins occur the MONOTONIC function may fail. Sounds like a fun experiment!
SPR
Quartz | Level 8 SPR
Quartz | Level 8
Hello Cynthia,
There is a solution without MONOTONIC():
[pre]
data tbl;
input first $1. second third fourth ;
row+1;
datalines;
a 21 22 23
s 31 32 33
d 41 42 43
f 51 52 53
run;
proc SQL;
create table mytbl(drop=row) as
select CATS("r",put(row,6.)) as myrownumber, * from tbl;
quit;
[/pre]
Sincerely,
SPR
Cynthia_sas
SAS Super FREQ
Hi:
Yes, that is probably what I would do if I needed a row-type identifier. As long as it is understood that when adding or deleting observations from the table, some action would need to be taken to redo the numbers and/or if sorting in some different order, then the numbers might appear out of their original order.

cynthia

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 1160 views
  • 0 likes
  • 4 in conversation