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

I have the following medicine dosage for each patient. I would like to set it missing once there is a 2nd treatment. See the new dosage column.

Patient IDMedicine datedosage# of dateTreatmentTreatment dateNew Dosage
11/13/20141327  132
11/14/20141328  132
11/15/20141329  132
11/16/201413210  132
11/17/201413211  132
11/18/201413212  132
11/19/201413213  132
11/20/201413214  132
11/21/201413215  132
11/22/201413216  132
11/23/201413217  132
11/24/201413218  132
11/25/201413219  132
11/26/201413220  132
11/27/201413221A27-Jan-14132
11/28/201413222 .132
11/29/201413223 .132
11/30/201441924A10-Feb-14 
11/31/201428625 . 
12/1/201428626 . 
12/2/201428627 . 
12/3/201428628 . 
12/4/201428629 . 
12/5/201428630 . 
12/6/201428631 . 
12/7/201428632 . 
12/8/201428633 . 
12/9/201428634 . 
12/10/201442135   
1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Assuming your data is sorted as in your example, you could use:

 

data want;

set have;

by patient_id;

if first.patient_id then n_treatments = 0;

if treatment='A' then n_treatments + 1;

if n_treatments < 2 then new_dosage = dosage;

drop n_treatments;

run;

View solution in original post

2 REPLIES 2
ballardw
Super User

It isn't clear if the data you show is what you have or what you want. Please clearly indicate what your data looks like Before the manipulation and then After the manipulation.

 

It also helps if you can provide your example data in the form of a datastep so we can test code. When you paste values we have to write a data step to read the code and may make choices that do not match your data. For example I do not know for sure which, if any, of your varaibles are character or numeric. If I make an assumption of type and write code to handle that but your data differs it is very likely the solution I propose will not work.

 

Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.

Astounding
PROC Star

Assuming your data is sorted as in your example, you could use:

 

data want;

set have;

by patient_id;

if first.patient_id then n_treatments = 0;

if treatment='A' then n_treatments + 1;

if n_treatments < 2 then new_dosage = dosage;

drop n_treatments;

run;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 652 views
  • 0 likes
  • 3 in conversation