DATA Step, Macro, Functions and more

flag

Reply
Regular Contributor
Posts: 168

flag

Hi All,

 

I am trying to flag the variable, which is not missing in particular vis, See the below sample data and code which i tried. any insight will be helpful. Thanks in advance

 

data have;

infile datalines truncover;

  input subj  visn val ;

  datalines;

    100  1 10

      100 24

      100 45 9

      101  1 12

      101 24 15

      101 45

      102  1

      102 24 15

      102 45 65

      103   1 10

      103  24 11

      103  45 15

      ;

run;

 

want:

    subj visn val  flg

      100  1    10   0 (non missing visn 1,24,45 (visn 24 val is missing)

      100 24         0 (non missing visn 1,24    (visn 24 val is missing

      100 45    9    1 (non missing visn 1,45     visn 1,45 val is not missing)

      101  1    12   0

      101 24    15   1

      101 45         0

      102  1         0

      102 24    15   0

      102 45    65   0

      103   1   10   1

      103  24   11   1

      103  45   15   1

 

code:

proc sort data=have; by subj visn;run;
data want;
  do until(last.visn);
  set have;
   by subj visn;
        if visn(1,24,45) & missing(val) then flg=0;
   else if visn in (1,24) & missing(val) then flg=0;
   else if visn in (1,45) & missing(val) then flg=0;
  end;
  do until(last.visn);
  set have;
   by subj visn;
   output;
  end;
run;

 

Thanks

Sam

Super User
Posts: 11,343

Re: flag

I think that you need to provide more of a description of how you are assigning flag values. For example in your want data

    subj visn val  flg
      100  1    10   0 (non missing visn 1,24,45 (visn 24 val is missing)
      100 24         0 (non missing visn 1,24    (visn 24 val is missing
      100 45    9    1 (non missing visn 1,45     visn 1,45 val is not missing)

you say Val is missing on the first line but it appears that the value of Val is 10.

 

Similar for

      101  1    12   0
      101 24    15   1

the rule(s) you are using don't seem to be clearly stated for why the first gets a 0 and the second gets a 1

 

 

Do you mean to say "If ANY of the values of the variable Val within an ID group is missing for VISN values of 1, 24 or 45 <then do something>?

 

You should also probably provide some values of VISN other than 1,24 and 45 so we have a chance to know what to do in that case.

Regular Contributor
Posts: 168

Re: flag

Hi Ballardw,

 

Thank you for the response!!! Apologies for not providing full information.

as my sample data shown, my data as only 3 visn (1,24,45). Need to flag 0 to below conditions:

 

VISN: non missing (val)

 

1  : subj with non-missing visn 1 and (visn 24 or visn 45)

24 : subj with non-missing visn 1 and visn 24

45: subj with non-missing visn 1 and visn 45

 

 

Thanks

Sam

Ask a Question
Discussion stats
  • 2 replies
  • 118 views
  • 0 likes
  • 2 in conversation