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