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
Your assignment is easy. I think I will be blamed by Art.T .
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
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.
Your assignment is easy. I think I will be blamed by Art.T .
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
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.