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.
You have not provided the log.
@PaigeMiller I am using a remote SAS interface without access to the usual browser features. See SAS log above.
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);
bup_value=bup(i); /*This worked*/
@PaigeMiller I misunderstood what you mean by "log". Does this mean inserting every line of code separately in </> ?
Copy the entire log for the data step, paste the entire log for the data step into the </> window.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.