Help using Base SAS procedures

sas query

Reply
Frequent Contributor
Posts: 145

sas query

I have dataeset with varaibles ID, VISIT, DAYS(Number of days). Visit can have values 'Screening' AND 'C1D1'.

We have to write edit check:

The Visit C1D1 has to be within 3 days (unless also screening is within 3 days)...if this is not satisfied..we have to output the discrepancies...

Thanks

Rakesh

Valued Guide
Posts: 858

Re: sas query

can you provide an example of the data you have?

Valued Guide
Posts: 858

Re: sas query

This might work for you, it depends on what the data looks like, a proc sql; sum group by could work too:

data have;

infile cards dsd;

length visit $10.;

input id $ visit $ days;

cards;

001,Screening,2

001,C1D1,3

002,Screening,4

002,C1D1,3

003,Screening,5

003,C1D1,4

;

run;

proc sort data=have;by id descending visit;

data want;

set have;

by id;

screen_days = lag(days);

if not first.id then do;

    if screen_days > 3 then do;

        if days > 3 then output;

    end;

end;

run;

Super User
Super User
Posts: 7,392

Re: sas query

Without test data, this is not tested, but something like:

proc sql;

     create table OUTLIERS as

     select     COALESCE(A.ID,B.ID) as ID,

                    A.DAYS as BASE,

                   B.DAYS as COMPARE,

                    case     when A.DAYS is null then "Base Missing"

                                 when B.DAYS is null then "Comp Missing"

                                 when A.DAYS is not null and B.DAYS is not null and B.DAYS - A.DAYS not between 0 and 3  then "Outside window" end as RESULT

     from       (select * from HAVE where VISIT="SCREENING") A

     full join   (select * from HAVE where VISIT="C1D1") B

     on          A.ID=B.ID;

quit;

You can filter on result.  note you do need to check if one or the other is missing.

Ask a Question
Discussion stats
  • 3 replies
  • 203 views
  • 3 likes
  • 3 in conversation