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

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: 

 

1Car1.2
1Motor1.2
1Van1.2
1Bike 1.2
1Ship1.2
1Car1.3
1Motor1.3
1Van1.3
1Bike 1.3
1Ship1.3
1Car1.4
1Motor1.4
1Van1.4
1Bike 1.4
1Ship1.4
1Car1.5
1Motor1.5
1Van1.5
1Bike 1.5
1Ship1.5

 

Many thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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;

View solution in original post

1 REPLY 1
Astounding
PROC Star

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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 1336 views
  • 1 like
  • 2 in conversation