For the below table, I need the first combination of "A, 194 and 2" to be duplicated or repeated 23 times and the second combination to be duplicated or repeated 14 times.
This code worked on another example but failed on this one. Any help?
do _N_= 1 to Domain;
output; end;
Error: "Invalid DO loop control information, either the INITIAL or TO expression is missing or the BY expression is missing, zero,
or invalid."
NAME | BR_CODE | BKT | Domain |
A | 194 | 2 | 23 |
A | 194 | 3 | 14 |
A | 194 | 4 | 8 |
Repeated 23 times...
BR_CODE | BKT | Domain | |
A | 194 | 2 | 23 |
A | 194 | 2 | 23 |
A | 194 | 2 | 23 |
A | 194 | 2 | 23 |
A | 194 | 2 | 23 |
A | 194 | 2 | 23 |
A | 194 | 2 | 23 |
A | 194 | 2 | 23 |
A | 194 | 2 | 23 |
A | 194 | 2 | 23 |
A | 194 | 2 | 23 |
A | 194 | 2 | …. |
A | 194 | 2 | …. |
A | 194 | 2 | …. |
A | 194 | 2 | …. |
I suspect this happens because Domain = . in one of the obs. Try this
data have;
input NAME $ BR_CODE BKT Domain;
datalines;
A 194 2 23
A 194 3 14
A 194 4 8
A 194 4 .
;
data want;
set have;
do _N_ = 1 to max(Domain, 0);
output;
end;
run;
I suspect this happens because Domain = . in one of the obs. Try this
data have;
input NAME $ BR_CODE BKT Domain;
datalines;
A 194 2 23
A 194 3 14
A 194 4 8
A 194 4 .
;
data want;
set have;
do _N_ = 1 to max(Domain, 0);
output;
end;
run;
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.