My seq variable goes from 1 to 6, but in my dataset the seq variable ends at 3. For graphing purposes i need to create a dataset as shown in my desired output below.
data have;
input subject seq source max min;
datalines;
12345 1 1 10 0
23456 2 1 10 0
34567 3 1 10 0
45678 4 1 10 0
56789 5 1 10 0
67890 6 1 10 0
78901 1 2 45 0
89012 2 2 45 0
90123 3 2 45 0
;
run;
I need to add observations to my original dataset, to complete the seq variable to 6. My max and min are related to source. So the additional observations will have respective source,max and min.
subject | seq | source | max | min |
12345 | 1 | 1 | 10 | 0 |
23456 | 2 | 1 | 10 | 0 |
34567 | 3 | 1 | 10 | 0 |
45678 | 4 | 1 | 10 | 0 |
56789 | 5 | 1 | 10 | 0 |
67890 | 6 | 1 | 10 | 0 |
78901 | 1 | 2 | 45 | 0 |
89012 | 2 | 2 | 45 | 0 |
90123 | 3 | 2 | 45 | 0 |
4 | 2 | 45 | 0 | |
5 | 2 | 45 | 0 | |
6 | 2 | 45 | 0 |
Any suggestions?
data have;
input subject seq source max min;
datalines;
12345 1 1 10 0
23456 2 1 10 0
34567 3 1 10 0
45678 4 1 10 0
56789 5 1 10 0
67890 6 1 10 0
78901 1 2 45 0
89012 2 2 45 0
90123 3 2 45 0
;
run;
data want;
set have end=last;
output;
if last then do;
do seq=seq+1 to 6;
call missing(subject);
output;
end;
end;
run;
data have;
input subject seq source max min;
datalines;
12345 1 1 10 0
23456 2 1 10 0
34567 3 1 10 0
45678 4 1 10 0
56789 5 1 10 0
67890 6 1 10 0
78901 1 2 45 0
89012 2 2 45 0
90123 3 2 45 0
;
run;
data want;
set have end=eof;
if eof then do while(seq<6);
seq+1;
call missing(subject);
output;
end;
retain seq source max min;
if seq < 6 then output;
run;
@gpv2000 For what graphing purposes do you need this?
data have;
input subject seq source max min;
datalines;
12345 1 1 10 0
23456 2 1 10 0
34567 3 1 10 0
45678 4 1 10 0
56789 5 1 10 0
67890 6 1 10 0
78901 1 2 45 0
89012 2 2 45 0
90123 3 2 45 0
;
run;
data want;
set have end=last;
output;
if last then do;
do seq=seq+1 to 6;
call missing(subject);
output;
end;
end;
run;
if the list is a pattern, like week1-weekN
you could use call missing(of week: ) ;
If you are using ODS graphics, have you considered options MIN= and MAX= in the XAXIS, COLAXIS, ROWAXIS, and YAXIS statements?
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.