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

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, , ,
;
1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 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;

View solution in original post

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 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;
ramgouveia
Obsidian | Level 7

@PeterClemmensen 

 

And if I want do do this only for var2 instead of var1, var2, and var3?

PeterClemmensen
Tourmaline | Level 20

@ramgouveia Sorry for the late reply. Did you find your answer?

ramgouveia
Obsidian | Level 7

@PeterClemmensen 

 

This one solved my problem.

 

Filling empty cells with other cells of the same column 

 

Thank you anyway.

sas-innovate-white.png

Register Today!

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.

Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1230 views
  • 1 like
  • 2 in conversation