Hello all and thank you in advance for any guidance!
I would like to use SAS to generate a dataset of fields as follows:
Site Patient
1 1001
1 1002
1 .....to 9999
2 1001
2 1002
2 ..... to 9999
.
.
99 .... to 9999
I want to basically create sequenced values for each field - site from 1-99 and patient from 1001-9999. Each site value would have patients in the range 1001-9999 up to 99 sites.
I tried many different ways but all seem to need data to exist already in order to make these. I can do this in excel but I know there must be a simple few lines of code to do this for me...
Thank you very much!
Basically, an empty dataset?
data want;
do Site=1 to 99;
do Patient=1001 to 9999;
output;
end;
end;
run;
If your Site and Patient id are truly sequential and all combinations are the same, just use do-loops in a data step with explicit output.
I did this (subset to smaller numbers for testing) and it worked. Thank you very much!
DATA T1;
retain siten 0 subject 1000;
do i=1 to 10;
Siten=siten+1;
output;
do t=1001 to 1010;
Subject=subject+1;
output;
end;
end;
run;
So I was wrong - it's almost right - any suggestions? I need subject to reset back to 1001 for each new site:
Obs siten subject i t
1 1 1001 1 .
2 1 1002 1 1001
3 1 1003 1 1002
4 1 1004 1 1003
5 1 1005 1 1004
6 1 1006 1 1005
7 1 1007 1 1006
8 1 1008 1 1007
9 1 1009 1 1008
10 1 1010 1 1009
11 1 1011 1 1010
12 2 1011 2 1011
13 2 1012 2 1001
14 2 1013 2 1002
15 2 1014 2 1003
16 2 1015 2 1004
17 2 1016 2 1005
18 2 1017 2 1006
19 2 1018 2 1007
20 2 1019 2 1008
21 2 1020 2 1009
See code in my solution above
You have an extra OUTPUT statement.
Reeza is right - simple code works perfectly. Thank you!
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.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.