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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

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
  • 3 replies
  • 4076 views
  • 4 likes
  • 3 in conversation