Hello all,
I am a beginner and I am trying to duplicate my dataset based on a condition. Every 6th observation the data set should be duplicated and range of numbers (1.2 to 1.5) needs to be added.
I am using the below code:
data have;
input ID sales;
datalines;
1 car
1 motor
1 van
1 bike
1 ship
;
data want;
set have;
do i= 1 to 5;
cost= 1.2;
output;
end;
run;
I need the output like below:
1 | Car | 1.2 |
1 | Motor | 1.2 |
1 | Van | 1.2 |
1 | Bike | 1.2 |
1 | Ship | 1.2 |
1 | Car | 1.3 |
1 | Motor | 1.3 |
1 | Van | 1.3 |
1 | Bike | 1.3 |
1 | Ship | 1.3 |
1 | Car | 1.4 |
1 | Motor | 1.4 |
1 | Van | 1.4 |
1 | Bike | 1.4 |
1 | Ship | 1.4 |
1 | Car | 1.5 |
1 | Motor | 1.5 |
1 | Van | 1.5 |
1 | Bike | 1.5 |
1 | Ship | 1.5 |
Many thanks!
I'm not sure what you mean by every 6th observation. But looking at the data coming in and the data set that you want:
data want;
set have;
do cost=1.2 to 1.5 by 0.1;
output;
end;
run;
Then if the order of the observations is important:
proc sort data=want;
by cost;
run;
I'm not sure what you mean by every 6th observation. But looking at the data coming in and the data set that you want:
data want;
set have;
do cost=1.2 to 1.5 by 0.1;
output;
end;
run;
Then if the order of the observations is important:
proc sort data=want;
by cost;
run;
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.