Hi, Can anybody tell me how to add a series number for every 70 subjects, for 14000 subjects. For example
subject series
00001 1
00002 1
00003 1
...
00071 2
00072 2
...
000141 3
..
13931 200
...
14000 200
Thanks!
If program minimization is the goal:
data want;
set have;
series= ceil(_n_/70);
run;
This technique can also be used when reading (and keeping 100%) of raw data:
data want;
infile 'c:\temp\mydatalines.txt';
input a b c … ;
series=ceil(_n_/70);
run;
Are you generating that data?
data want;
do series=1 to 200;
do _n_=1 to 70 ;
subject_num+1;
subject=put(subject_num,z5.);
output;
end;
end;
run;
Or generating SERIES for an existing dataset.
You can either count them yourself by placing the SET/OUTPUT statements inside a DO loop.
data want;
series+1;
do _n_=1 to 70;
set have ;
output;
end;
run;
or convert the observation counter. So 1-70 is mapped to 1 and 71-140 is mapped to 2, etc.
data want;
set have ;
series = 1+int((_n_-1)/70);
run;
data have;
do _n_=1 to 14000;
subect=put(_n_,z5.); output;
end;
run;
data want;
set have;
retain series 1;
_iorc_=mod(_n_,70);
if _iorc_ eq 0 then series +1;
run;
If program minimization is the goal:
data want;
set have;
series= ceil(_n_/70);
run;
This technique can also be used when reading (and keeping 100%) of raw data:
data want;
infile 'c:\temp\mydatalines.txt';
input a b c … ;
series=ceil(_n_/70);
run;
Thank you so much! Really helpful.
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!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: