BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
gpv2000
Calcite | Level 5

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.

 

subjectseqsourcemaxmin
1234511100
2345621100
3456731100
4567841100
5678951100
6789061100
7890112450
8901222450
9012332450
 42450
 52450
 62450

Any suggestions?

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
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;

View solution in original post

7 REPLIES 7
PeterClemmensen
Tourmaline | Level 20
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? 

novinosrin
Tourmaline | Level 20
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;
gpv2000
Calcite | Level 5
Thank you. It does what I need, but i have a question. I believe I will have to add the variables i need to keep missing next to usubjid. How do I add variables if i have various such as week1,week2,weekn etc?
novinosrin
Tourmaline | Level 20

if the list is a pattern, like week1-weekN

 

you could use call missing(of week: ) ;

gpv2000
Calcite | Level 5
Thank you.
PGStats
Opal | Level 21

If you are using ODS graphics, have you considered options MIN= and MAX= in the XAXIS, COLAXIS, ROWAXIS, and YAXIS statements?

PG
gpv2000
Calcite | Level 5
I am fairly new sas user. I believe i am not using ODS graphics. But I will look it up now.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 1491 views
  • 0 likes
  • 4 in conversation