DATA Step, Macro, Functions and more

Simple question on setting up missing values

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 10
Accepted Solution

Simple question on setting up missing values

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

 


Accepted Solutions
Solution
‎03-20-2018 11:13 PM
PROC Star
Posts: 8,115

Re: Simple question on setting up missing values

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

 

 

View solution in original post


All Replies
Regular Contributor
Posts: 160

Re: Simple question on setting up missing values

data test2; set test;
by sub;
if not first.sub then do;bmi=.; age=.; end;
run;

Solution
‎03-20-2018 11:13 PM
PROC Star
Posts: 8,115

Re: Simple question on setting up missing values

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

 

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 79 views
  • 2 likes
  • 3 in conversation