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.

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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