BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
art297
Opal | Level 21

Sort of .. kind of.  You would have to change some of the code. e.g.:

data have;

  input ID $  Diag   ReadmitID $;

  cards;

101     4            111

102     3            222

103    5            333

111    4 .

222    4 .

333     6 .

;

DATA fmtDataset (drop=ReadmitID);

  set have (rename=(id=start diag=label));

  if missing(ReadmitID);

  retain fmtname 'idcode' type 'C';

RUN;

PROC FORMAT CNTLIN=fmtDataset;

RUN;

DATA want;

  set have;

  if not missing(ReadmitID);

  if put(ReadmitID,$idcode.) eq diag then same='yes';

  else same='no';

RUN;

P.S.  Isn't it about time that you marked some of the posts in this thread as being either helpful or correct or, minimally, at least indicate that the question has been answered.

robertrao
Quartz | Level 8

Art,

I will not forget to do that...Thanks for the reminder

Yesterday I went home too early and could not respond to the answers posted by the team.

I am doing right away

Thanks

art297
Opal | Level 21

Maybe you would still consider this one simple:

data have;

  input ID $  Diag   ReadmitID $;

  cards;

A     4            A'

B     3            B'

C     5           C'

A'     4 .

B'     4 .

C'     6 .

;

data first;

  set have (where=(index(id,"'")=0));

run;

proc sort data=first;

  by ReadmitID;

run;

data second;

  set have (drop=ReadmitID

            rename=(ID=ReadmitID

                    diag=diag2)

            where=(index(ReadmitID,"'")));

run;

proc sort data=second;

  by ReadmitID;

run;

data want;

  merge first second;

  by ReadmitID;

  if diag eq diag2 then same="Yes";

  else same="No";

run;

Astounding
PROC Star

karun,

The second SET statement reads all the observations, and compares each to the observation read by the first SET statement.

The observation read by the first SET statement matches observation # _n_.  The observation read by the second SET statement matches observation # _i_, since that second SET statement uses POINT=_i_ to control which observation to read.

Lots of interesting solutions here.

Good luck.

Haikuo
Onyx | Level 15

How about a little Hash() approach:

data have;

infile cards truncover;

input (ID   Diag   ReadmitID) (:$);

cards;

A     4            A'

B     3            B'

C     5           C'

A'     4

B'     4

C'     6

;

data want;

  if _n_=1 then do;

    if 0 then set have (rename=(diag=_diag id=_id) keep=id diag);

    dcl hash h(dataset:"have(rename=(diag=_diag id=_id) keep=id diag)");

    h.definekey('_ID');

    h.definedata(all:'y');

    h.definedone();

  end;

  set have;

    if h.find(key:ReadmitID)=0 then flag=(diag=_diag);

    drop _:;

  run;

  proc print;run;

Haikuo

RichardinOz
Quartz | Level 8

If you are only interested in readmissions, and there can only be a single readmission per patient, then this will do it in one pass

Proc SQL ;

    Create table readmit as

        Select    adm.ID

            ,    adm.Diag

            ,    adm.ReadmitID

            ,    rad.Diag    As    ReadmitDiag

            ,    case (rad.Diag)

                    When (adm.Diag)

                        Then    'Y'

                        Else    'N'

                    End

                            As    Match

        From    admit    adm

              ,    admit    rad

        Where    rad.ID    =    adm.ReadmitID

                ;

Quit ;

However, if you want a more general solution where the possibility of multiple readmissions exists then it would be better to recode the readmission ID to match the original admission, then process the resulting dataset for non matches.  If this is the case, I could suggest some code.

Richard in Oz

Ksharp
Super User

HaiKuo's code maybe is the fastest way.Here is another SQL solution.

Data is from ArthurT.

data have;
  input ID $  Diag   ReadmitID $;
  cards;
A     4            A'
B     3            B'
C     5           C'
A'     4 .
B'     4 .
C'     6 .
;
run;
proc sql;
 create table want as
 select h.*,case when h.diag eq (select diag from have where id eq h.ReadmitID) then 'Yes'
               when h.diag ne (select diag from have where id eq h.ReadmitID) then 'No'
          else 'No matched' end as flag length=10
  from have as h
;
quit;


Ksharp

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
  • 21 replies
  • 1386 views
  • 6 likes
  • 6 in conversation