sippstress
sippstress

Reputation: 33

give variables in an array the value of variables in another array

So, I have a range of sas dates (18141 to 18414) and a range of id numbers (m101-m254). I want to have every value in the date range appear once for every value in the id range such that

date  id
18141 m101
18142 m101
18143 m101
..    ..
18414 m102
18141 m102
18142 m102
18143 m102
..    ..
18414 m102

etc

I have been trying this:

data data;
array linx (274) d18141-d18414;
array ids(154) m101-m254;
retain d18141-d18414 m101-m254;
do i=1 to 274;
do j=1 to 154;
linx(i)=ids(j);
end;
end;
run;

but sas just sticks the two arrays together side-by-side. Any ideas? Thanks!

Upvotes: 1

Views: 61

Answers (1)

Joe
Joe

Reputation: 63424

Arrays aren't really the right way to handle this. Arrays are across a single row; you're doing this with rows, not columns.

A plain old do loop will do this for you, with the output statement.

data want;
do id_n=101 to 254;
  do date='18141'd to '18414'd;
    id=cats('m',id_n);
    output;
  end;
end;
run;

Upvotes: 1

Related Questions