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

Hi All -

I'm working on an assignment that requires me to get the output below from data testing. I'm not even sure where to start. Anyone have any suggestions / techniques?


data testing;

     input subject dose startmonth endmonth;

cards;

1  25   0   3

1  25   3   5

1  50   5   7

1  50   7   9

1  50   9   12

1   .   12  14

1  25   14  16

2  50   0   3

2  50   3   5

2  25   5   7

2  25   7   9

2  50   9   12

2   .   12  14

2  .   14  16

;

run;

Output that I’m trying to get:

Subject     DosingPattern     DosingTime

1           25#50#.#25        5#7#2#2

2           50#25#50#.        5#4#3#4

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

Your assignment is easy. I think I will be blamed by Art.T . Smiley Happy

data testing;
     input subject dose startmonth endmonth;
cards;
1  25   0   3
1  25   3   5
1  50   5   7
1  50   7   9
1  50   9   12
1   .   12  14
1  25   14  16
2  50   0   3
2  50   3   5
2  25   5   7
2  25   7   9
2  50   9   12
2   .   12  14
2  .   14  16
;
run;
data x(keep=subject dose duration);
 set testing;
 by subject dose notsorted;
 retain start;
 if first.dose then start=startmonth;
 if last.dose then do;duration=endmonth-start;output;end;
run;
data want(keep=subject pattern time);
 set x;
 by subject notsorted;
 length pattern time $ 400;
 retain pattern time;
 pattern=catx('#',pattern,dose);
 time=catx('#',time,duration);
 if last.subject then do;output;call missing(pattern,time);end;
run;



Ksharp

View solution in original post

2 REPLIES 2
art297
Opal | Level 21

You say assignment, thus can we assume homework assignment?

If so, most people here don't mind helping, but only if you try.  And, of course, no one here would know what you have been taught and how complex of an answer you can handle.

If you look at your data, for each subject, the doses follow the DosingPattern you want to end up with and the endmonth-startmonth for each matches your DosingTime desired entries.

This could be done, minimally, in a datastep or with proc sql.

If you do it with a datastep, one way would be to use a by Subject dose statement, first.dose and last.dose variables to know when you've got the starting and ending information, a retain statement to retain the desired variables you are trying to create, as well as to retain the DosingTime sums.

Does any of that make sense to you?  If it does, try to write the code and, if you run into a problem, ask a more specific question as to how you would have to correct "your" code to get it to work.

Ksharp
Super User

Your assignment is easy. I think I will be blamed by Art.T . Smiley Happy

data testing;
     input subject dose startmonth endmonth;
cards;
1  25   0   3
1  25   3   5
1  50   5   7
1  50   7   9
1  50   9   12
1   .   12  14
1  25   14  16
2  50   0   3
2  50   3   5
2  25   5   7
2  25   7   9
2  50   9   12
2   .   12  14
2  .   14  16
;
run;
data x(keep=subject dose duration);
 set testing;
 by subject dose notsorted;
 retain start;
 if first.dose then start=startmonth;
 if last.dose then do;duration=endmonth-start;output;end;
run;
data want(keep=subject pattern time);
 set x;
 by subject notsorted;
 length pattern time $ 400;
 retain pattern time;
 pattern=catx('#',pattern,dose);
 time=catx('#',time,duration);
 if last.subject then do;output;call missing(pattern,time);end;
run;



Ksharp

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
  • 2 replies
  • 1029 views
  • 4 likes
  • 3 in conversation