BookmarkSubscribeRSS Feed
renjithr
Quartz | Level 8

   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

6 REPLIES 6
Reeza
Super User

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

renjithr
Quartz | Level 8

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.

Reeza
Super User

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

renjithr
Quartz | Level 8

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.

Tom
Super User Tom
Super User

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;

renjithr
Quartz | Level 8

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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

New Learning Events in April

 

Join us for two new fee-based courses: Administrative Healthcare Data and SAS via Live Web Monday-Thursday, April 24-27 from 1:00 to 4:30 PM ET each day. And Administrative Healthcare Data and SAS: Hands-On Programming Workshop via Live Web on Friday, April 28 from 9:00 AM to 5:00 PM ET.

LEARN MORE

Discussion stats
  • 6 replies
  • 2359 views
  • 0 likes
  • 3 in conversation