BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
femiajumobi1
Quartz | Level 8

A. 

I have this data (short) with 50 date variables DFS_Fam1 - DFS_Fam50. Some observations do not have date value for DFS_Fam1 - DFS_Fam50

I want to create variables that show if a date value is available, it is indicated as 1, and no date value = 0 or missing. 

 

           ID              DFS_Fam1               DFS_Fam2                 DFS_Fam3

           1                01/01/2023              02/01/2023                   03/01/2023 

           2                04/01/2023              05/01/2023                   06/01/2023 

           3                05/01/2023                                 

 

For example for observation 1, if DFS_Fam1, DFS_Fam2, DFS_Fam3 have date values, then New_A1=1, New_A2=1, New_A3=1 as shown (but up to whenever DFS_Fam has dates)

           ID              DFS_Fam1               DFS_Fam2                 DFS_Fam3        New_A1       New_A2   New_A3

           1                01/01/2023              02/01/2023                   03/01/2023         1                   1               1

           2                04/01/2023              05/01/2023                   06/01/2023         1                   1               1

           3                05/01/2023                                                                              1                     

 

This is clinical data, everyone has DFS_Fam1 but not necessary  DFS_Fam2 ,  DFS_Fam3 up to  DFS_Fam50, thus there would be missing dates.

 

How do I go about these without writing 50 lines of code?

 

B. I would like to convert New_A to time points

Data long;

set short;

New=New_A1; time=0; output;

New=New_A2; time=1; output;

New=New_A3; time=2; output;

...        ....          .........     .......

New=New_A50; time=50; output;

 

How do I go about these without writing 50 lines of code?

Thanks.

data want;
    set have;
    array dfs dfs_:
    array new new_a1-new_a50;
    do i=1 to dim(dfs);
        if not missing(dfs(i)) then new(i)=1;
        else new(i)=0;
    end;
    drop i;
run;
data want;
    set have;
    array dfs dfs_:
    array new new_a1-new_a50;
    do i=1 to dim(dfs);
        if not missing(dfs(i)) then new(i)=1;
        else new(i)=0;
    end;
    drop i;
run;
data want;
set have;
array dfa_fam dfa_fam1-dfa_fam50:
array new new_a1-new_a50;
array time t1-t50;
do i=1 to dim( dfa_fam);
if not missing(dfa_fam(i)) then new(i)=1;
else new(i)=0;
if not missing(new(i)) then time(i)=1;
else time(i)=0;
end;
drop i;
run;

Proc transpose data =want out =wanted;
by time;
run;
data want;
set have;
array dfa_fam dfa_fam1-dfa_fam50:
array new new_a1-new_a50;
array time t1-t50;
do i=1 to dim( dfa_fam);
if not missing(dfa_fam(i)) then new(i)=1;
else new(i)=0;
if not missing(new(i)) then time(i)=1;
else time(i)=0;
end;
drop i;
run;
data want;
set have;
array dfa_fam dfa_fam1-dfa_fam50:
array new new_a1-new_a50;
array time t1-t50;
do i=1 to dim( dfa_fam);
if not missing(dfa_fam(i)) then new(i)=1;
else new(i)=0;
if new(i)>0 then do;
     time=i-1;
     new=new(i);
     output;
end;
drop i;
run;

@PaigeMiller here is the list of data steps as per our communication. Thanks. 

PaigeMiller
Diamond | Level 26

You have not provided the log.

--
Paige Miller
femiajumobi1
Quartz | Level 8

@PaigeMiller I am using a remote SAS interface without access to the usual browser features. See SAS log above.

PaigeMiller
Diamond | Level 26

Thank you for showing me the log. I point out that I gave specific instructions for you to provide the log, which you did not follow. From now on, I expect you to follow those instructions for providing the log. Screen captures are not usually acceptable.

 

Instead of 

 

bup=bup(i);

 

try this

 

bup_value=bup(i);

 

 

--
Paige Miller
femiajumobi1
Quartz | Level 8

 

bup_value=bup(i); /*This worked*/

 

 

 

@PaigeMiller I misunderstood what you mean by "log".  Does this mean inserting every line of code separately in </> ?

PaigeMiller
Diamond | Level 26

Copy the entire log for the data step, paste the entire log for the data step into the </> window.

--
Paige Miller
Reeza
Super User
This means that the variables are a combination of numeric and character types.
You may need to clean up the data before this step to ensure all dates are SAS numeric dates or character dates (not recommended).