BookmarkSubscribeRSS Feed
rakeshvvv
Quartz | Level 8

I have dataset with two variables ID, VISIT…

Every ID should have screening and cycle1 as visit values….So VISIT should have two values(SCREENING, CYCLE1)….. I want  to write a query in such way……I Should output records where any of the visits values are missing for that ID. EX: For any ID if either of SCREENING OR CYCLE1 is missing then it is discrepancy...

Thanks

Raghav

5 REPLIES 5
ballardw
Super User

Please show some example data and the expected results. Do you want the results in a SAS data set or a report document?

Steelers_In_DC
Barite | Level 11

I think this is what you are looking for:

data have;

infile cards dsd;

length id visit $9.;

input ID $ visit $;

cards;

100,Screening

100,Cycle1

101,Cycle1

102,Screening

103,Screening

103,,

104,,

104,Cycle1

;

run;

data want good;

set have;

by id;

if (first.id and last.id) or missing(visit) then output want;

run;

slchen
Lapis Lazuli | Level 10

proc sql;

     select * from have group by id having count(*)=1 or missing(visit);

quit;

Steelers_In_DC
Barite | Level 11

I replied already but I like this one better.  Should test this vs proc sql if it's a big dataset to see how the timing difference is:

data have;

infile cards dsd;

length id visit $9.;

input ID $ visit $;

cards;

100,Screening

100,Cycle1

101,Cycle1

102,Screening

103,Screening

103,,

104,,

104,Cycle1

;

run;

data bad(drop=flag flag2) good(drop=flag flag2);

do until (last.id);

set have;

by id;

if visit = 'Screening' then flag = 1;

if visit = 'Cycle1' then flag2 = 1;

end;

do until (last.id);

set have;

by id;

if flag = 1 and flag2 = 1 then output good;

if flag ne 1 or flag2 ne 1 then output bad;

end;

run;

PGStats
Opal | Level 21

To do this with a datastep :

data have;

infile cards dsd;

length id visit $9;

input ID visit;

cards;

100,Screening

100,Cycle1

101,Cycle1

102,Screening

103,Screening

103,

104,Other

105,

105,Cycle1

;

proc sort data=have; by id visit; run;

data want;

merge

    have

    have(where=(visit="Cycle1") in=inC)

    have(where=(visit="Screening") in=inS);

by id;

Cycle1_present = inC;

Screening_present = inS;

Discrepancy = not (Cycle1_present and Screening_present);

if first.id;

keep id Screening_present Cycle1_present Discrepancy;

run;

proc print data=want noobs; run;

PG

PG

sas-innovate-2024.png

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.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1014 views
  • 1 like
  • 5 in conversation