counting process

Reply
Occasional Contributor
Posts: 7

counting process

Hello,

I am trying to transform my data into long format data, i need to know if there is any macro sas or paper that i can refer to ? 

i know there is  msprep and expand.covs in R to have multiple line for each variable change but i can't find any macro sas for that.

Thank you in advance for your help,

 

 

Super User
Posts: 10,035

Re: counting process

Occasional Contributor
Posts: 7

Re: counting process

Thank you for your help,

I tried to use these optipns with proc transpose but i didn't get what i need.

I will illustrate my idea with an example:

i would like to transhorm the data in table 1 to a long format data [start, stop] like in the table 2 .

table1 :

Nirfolllow upeventHypertensiondiabetescancer
1570232611
242011370
3561 0200
42509 00

 

table 2:

NirStartstophypertensiondiabetescancerevent
10110000
111230010
123261010
126571110
20110000
211371000
237421100
30200000
320560101
4090000
49251000

 

Thank you in advance,

Aya

Valued Guide
Posts: 860

Re: counting process

This will get you to the desired output.  I feel like there is an exceptional amount of explanation that is left out so I don't know if this will work with your real life data.  I'm learning hash and will work on an iterative hash solution to this that will save time on a large dataset but I wouldn't hold my breath on that as I'm not sure I'll get to a solution in my free time:

 

data have;
infile cards dsd;
input Nir    follow_up    event    Hypertension    diabetes    cancer;
cards;
1,57,0,23,26,11
2,42,0,11,37,0
3,56,1,0,20,0
4,25,0,9, 0,0
;
run;

data stops;
set have;
stop=cancer;output;
stop=hypertension;output;
stop=diabetes;output;
stop=follow_up;output;
run;

data prep;
set stops;
by nir;
if stop = 0 then delete;
start=lag(stop);
run;

data want;
set prep;
by nir;
if first.nir then do;start = 0;event=0;end;
if 0<cancer<stop then cancer=1;else cancer=0;
if 0<Hypertension<stop then Hypertension=1;else Hypertension=0;
if 0<diabetes<stop then diabetes=1;else diabetes=0;
run;

proc sql;
select nir,start,stop,hypertension,diabetes,cancer,event
from want;

Super User
Posts: 10,035

Re: counting process

data have;
infile cards dsd;
input Nir    follow_up    event    Hypertension    diabetes    cancer;
cards;
1,57,0,23,26,11
2,42,0,11,37,0
3,56,1,0,20,0
4,25,0,9, 0,0
;
run;
data want;
 set have;
 array x{4} follow_up Hypertension    diabetes    cancer;
 array y{4} ;
 array z{4} dummy _Hypertension    _diabetes    _cancer;
 
 do i=1 to 4;
  z{i}=0;
 end;
 
 do i=1 to 4;
  if x{i} gt 0 then y{i}=x{i};
 end;
 call sortn(of y{*});
 
 start=0;
 do i=1 to 4;
  if not missing(y{i}) then do;
    stop=y{i};
    if event=1 then do;event=0;has_event=1;end;
    if start gt 0 then do;
      idx=whichn(start,of x{*}) ;
      z{idx}=1;                     
    end;
    if follow_up=stop and has_event then event=1; 
    output;
    start=stop;   
  end;
 end;
drop y1-y4 follow_up Hypertension has_event dummy   diabetes    cancer i idx;
run;
 
Occasional Contributor
Posts: 7

Re: counting process

It works ! Thank you very much for this help !!

Ask a Question
Discussion stats
  • 6 replies
  • 432 views
  • 0 likes
  • 4 in conversation