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?
Obs | Values | Sums |
---|---|---|
1 | 440 | 440 |
2 | 450 | 890 |
3 | 430 | 1320 |
4 | 440 | 1760 |
5 | 440 | 2200 |
6 | 450 | 2650 |
7 | 450 | 3100 |
8 | 440 | 3540 |
9 | 360 | 3900 |
10 | 280 | 4180 |
Thanks,
Lucy
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
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
Ah thanks! Exactly what i wanted.
-Lucy
data test1;
set test;
obs = _n_;
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.