BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
lucysas
Fluorite | Level 6

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

1 ACCEPTED SOLUTION

Accepted Solutions
Haikuo
Onyx | Level 15

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

View solution in original post

3 REPLIES 3
Haikuo
Onyx | Level 15

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

lucysas
Fluorite | Level 6

Ah thanks! Exactly what i wanted.

-Lucy

Hima
Obsidian | Level 7

data test1;

set test;

obs = _n_;

run;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 4575 views
  • 4 likes
  • 3 in conversation