How to split DX for an encounter into multiple rows?

Reply
Frequent Contributor
Posts: 122

How to split DX for an encounter into multiple rows?

   Hi All,

Could you please help me with this problem.

My file has the following fields:

ID    rgn_cd   dx1   dx2  dx3....dxn

100  01          200   300  400 ... 110

I want to create an output file like this:

ID         rgn_cd  dx1   dx2     dx3 .....    dxn

100        01       200  

100        01                300

100        01                        400

...          ---                                  ------

      

100(n)    01(n)                                         110

Please share your thoughts

Super User
Posts: 18,988

Re: How to split DX for an encounter into multiple rows?

Don't.  That file structure makes very little sense, what would be the benefit?

A long structure is better, and you can use proc transpose to get it.

ID    rgn_cd   dx dx_code

100  01         1  200 

100  01          2 300

...

100  01        n 110

101 01        1 201

Frequent Contributor
Posts: 122

Re: How to split DX for an encounter into multiple rows?

Hi

The  request was to modify the output file like I mentioned above to tally the dx for the client, I agree that long structure is better but that is not what my client wants.

Super User
Posts: 18,988

Re: How to split DX for an encounter into multiple rows?

How would you tally the DX for the client with that structure, compared to the long structure?

Frequent Contributor
Posts: 122

Re: How to split DX for an encounter into multiple rows?

I think what the client wants is to count the rows for an encounter and compare that count with the total DX codes.

for eg: an ecnounter 101 has 4 dx codes then the output file will have 4 rows for that encounter.

Super User
Super User
Posts: 6,842

Re: How to split DX for an encounter into multiple rows?

Use arrays and a DO loop.

%let n=10 ;

data want ;

   set have;

   array _dx dx1-dx&n ;

   array save(&n) $5 _temporary_ ;

  do _n_=1 to &n ;

    save(_n_)=_dx(_n_) ;

  end;

   call missing(of dx1-dx&n);

  do _n_=1 to &n ;

    _dx(_n_)=save(_n_);

    output;

  end;

run;

Frequent Contributor
Posts: 122

Re: How to split DX for an encounter into multiple rows?

Hi Tom,

Thanks so much for your input. With a slight modification I was able to get what I wanted.

Below is the modified code:

%let n=10 ;

data want ;

   set have;

   array _dx dx1-dx&n ;

   array save(&n) $5 _temporary_ ;

  do _n_=1 to &n ;

    save(_n_)=_dx(_n_) ;

  end;


  do _n_=1 to &n ;

        call missing(of dx1-dx&n);

    _dx(_n_)=save(_n_);

    output;

  end;

run;

Ask a Question
Discussion stats
  • 6 replies
  • 1652 views
  • 0 likes
  • 3 in conversation