I have this code
data have;
infile datalines dlm=',' dsd;
input ID $ var1 $ var2 $ var3 $;
datalines;
ID 00, ,Y,
ID 00, , ,
ID 00,Y, ,
ID 01,Y, ,Y
ID 01, , ,
;
data want;
do until (last.id);
update have(obs=0) have;
by ID;
end;
do until (last.id);
set have (keep=id); by id;
output;
end;
run;
I got this code here:
https://communities.sas.com/t5/SAS-Programming/assign-the-same-value-by-group/td-p/717919
Instead of grouping by one variable I want to group by two or more variables. How can I adapt the code to this dataset?
data have2;
infile datalines dlm=',' dsd;
input ID_A $ ID_B $ var1 $ var2 $ var3 $;
datalines;
ID 00, ID 10, ,Y,
ID 00, ID 10, , ,
ID 00, ID 20,Y, ,
ID 00, ID 20, , ,
ID 01, ID 10,Y, ,Y
ID 01, ID 10, , ,
ID 01, ID 20, ,Y,
ID 01, ID 20, , ,
;
Try this
data have2;
infile datalines dlm=',' dsd;
input ID_A $ ID_B $ var1 $ var2 $ var3 $;
datalines;
ID 00, ID 10, ,Y,
ID 00, ID 10, , ,
ID 00, ID 20,Y, ,
ID 00, ID 20, , ,
ID 01, ID 10,Y, ,Y
ID 01, ID 10, , ,
ID 01, ID 20, ,Y,
ID 01, ID 20, , ,
;
data want;
do until (last.ID_B);
update have2(obs=0) have2;
by ID_A ID_B;
end;
do until (last.ID_B);
set have2 (keep=ID_A ID_B);
by ID_A ID_B;
output;
end;
run;
Try this
data have2;
infile datalines dlm=',' dsd;
input ID_A $ ID_B $ var1 $ var2 $ var3 $;
datalines;
ID 00, ID 10, ,Y,
ID 00, ID 10, , ,
ID 00, ID 20,Y, ,
ID 00, ID 20, , ,
ID 01, ID 10,Y, ,Y
ID 01, ID 10, , ,
ID 01, ID 20, ,Y,
ID 01, ID 20, , ,
;
data want;
do until (last.ID_B);
update have2(obs=0) have2;
by ID_A ID_B;
end;
do until (last.ID_B);
set have2 (keep=ID_A ID_B);
by ID_A ID_B;
output;
end;
run;
@ramgouveia Sorry for the late reply. Did you find your answer?
This one solved my problem.
Filling empty cells with other cells of the same column
Thank you anyway.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Early bird rate extended! Save $200 when you sign up by March 31.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.