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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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