Hello all,
I am struggling on a simple program. I wanted to assign missing values for all the BMI and age that have duplicate records.
data test;
input sub bmi age med$;
datalines;
1 0.2 12 ibuprofen
1 0.2 12 crocin
1 0.2 12 cetrizine
2 0.3 14 rituxim
2 0.3 14 belimu
;
My output data set should have multiple records for subject ID but missing values for BMI and age that are duplicates. My output should look like below.Thanks for your help.
1 0.2 12 ibuprofen
1 . . crocin
1 . . cetrizine
2 0.3 14 rituxim
2 . . belimu
Depends upon what you consider duplicates. Possibly you're looking for something like:
data test; input sub bmi age med$; datalines; 1 0.2 12 ibuprofen 1 0.2 12 crocin 1 0.2 12 cetrizine 2 0.3 14 rituxim 2 0.3 14 belimu ; data test2; set test; by sub bmi age; if not first.age then do; call missing(bmi); call missing(age); end; run;
Art, CEO, AnalystFinder.com
data test2; set test;
by sub;
if not first.sub then do;bmi=.; age=.; end;
run;
Depends upon what you consider duplicates. Possibly you're looking for something like:
data test; input sub bmi age med$; datalines; 1 0.2 12 ibuprofen 1 0.2 12 crocin 1 0.2 12 cetrizine 2 0.3 14 rituxim 2 0.3 14 belimu ; data test2; set test; by sub bmi age; if not first.age then do; call missing(bmi); call missing(age); end; run;
Art, CEO, AnalystFinder.com
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.