0

Have two datasets, one one row, the other 100 rows. I want to set them together horizontally (not merge) and copy down the one row to all 100 rows.

Right now I make a loop to copy down the rows of the smaller dataset, however its not very efficient and filling up my log. Looking for a cleaner way.

data sample_ds1;
infile datalines dlm=',';
input country $ maternal_2004 maternal_2005;
datalines;
MS,5,0
Mi,3,0
Mu,4,0
My,5,0
Mr,6,0
Mw,7,0
Mj,8,0
;

data sample_ds12temp;
infile datalines dlm=',';
input MEAN;
datalines;
3.5
;

data sample_ds12;
  set sample_ds12temp;
  run;

  do i=1 to 10;
  proc append base=sample_ds12 data=sample_ds12temp; run;
   end;

data together;
set sample_ds1;
set sample_ds1;
run; 
Cœur
  • 37,241
  • 25
  • 195
  • 267
aky
  • 11
  • 1
  • Do you want to add the constant from the single observation dataset to all observations in your other dataset? – Jonas Aug 12 '15 at 14:34
  • What does "not merge" mean? Set together horizontally is merge, as far as SAS terminology goes: merge [horizontal] or append [vertical]. If you mean you don't want to merge by a variable, that's fine. – Joe Aug 12 '15 at 15:40
  • Providing an example of what the output dataset would look like would be helpful. – Robert Penridge Aug 12 '15 at 16:40

1 Answers1

0

If i understand your question correct then this should do the trick.

data A;
infile datalines dlm=',';
input country $ maternal_2004 maternal_2005;
datalines;
MS,5,0
Mi,3,0
Mu,4,0
My,5,0
Mr,6,0
Mw,7,0
Mj,8,0
;

data B;
infile datalines dlm=',';
input MEAN;
datalines;
3.5
;

data test;
if _n_=1 then set B;
set A;
run;
Jonas
  • 321
  • 1
  • 6
  • 1
    This is the right approach. However, you should add some explanation for why it works - code-only answers are not good answers. – Joe Aug 12 '15 at 15:39