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.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.