## using the Obs column

Solved
Occasional Contributor
Posts: 8

# using the Obs column

Hi,

I'd like to be able to use the values in the Obs column (that SAS adds when using print) in my calculations. Is this possible? If not, how can I add a column of numbers to an existing table?

ObsValues
Sums
1440440
2450890
34301320
44401760
54402200
64502650
74503100
84403540
93603900
102804180

Thanks,

Lucy

Accepted Solutions
Solution
‎02-22-2012 12:55 PM
Posts: 3,167

## using the Obs column

Lucy,

Take a look at automatic variable '_n_', it maybe what you need:

data want;

input Values     Sums;

n=_n_;

cards;

440     440

450     890

430     1320

440     1760

440     2200

450     2650

450     3100

440     3540

360     3900

280     4180

;

proc print;run;

if you are using proc sql, there is undocumented function monotonic () that you can use, or using ODS to get the obs number.

Regards,

Haikuo

All Replies
Solution
‎02-22-2012 12:55 PM
Posts: 3,167

## using the Obs column

Lucy,

Take a look at automatic variable '_n_', it maybe what you need:

data want;

input Values     Sums;

n=_n_;

cards;

440     440

450     890

430     1320

440     1760

440     2200

450     2650

450     3100

440     3540

360     3900

280     4180

;

proc print;run;

if you are using proc sql, there is undocumented function monotonic () that you can use, or using ODS to get the obs number.

Regards,

Haikuo

Occasional Contributor
Posts: 8

## using the Obs column

Ah thanks! Exactly what i wanted.

-Lucy

Regular Contributor
Posts: 233

## using the Obs column

data test1;

set test;

obs = _n_;

run;

🔒 This topic is solved and locked.

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

Discussion stats
• 3 replies
• 1054 views
• 0 likes
• 3 in conversation