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

I am stuck to this prob;em please help me out:

 

A bike deliver a milage of 20 miles per gallon. write a code in SAS so that the code stops generating observations when distance reaches 250 miles or when 10 gallons of fuel  have ben used.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Jagadishkatam
Amethyst | Level 16

Consider that you have a dataset with miles and you want to create a new dataset creating a new variable and if this new variable values reaches the 250 mark then you need to stop. Use the do until as i used.

 

data have;
do miles=100 to 1000 by 50;
output;
end;
run;

data want;
do until(mile<=250);
set have;
mile=miles;
end;
run;
Thanks,
Jag

View solution in original post

5 REPLIES 5
art297
Opal | Level 21

What have you tried?

 

Art, CEO, AnalystFinder.com

Nishant_saxena
Calcite | Level 5

I was trying some stuff like:

 

data milage;
do gallons= 1 to 10;
while(distance<250);
run;

Jagadishkatam
Amethyst | Level 16

Consider that you have a dataset with miles and you want to create a new dataset creating a new variable and if this new variable values reaches the 250 mark then you need to stop. Use the do until as i used.

 

data have;
do miles=100 to 1000 by 50;
output;
end;
run;

data want;
do until(mile<=250);
set have;
mile=miles;
end;
run;
Thanks,
Jag
Nishant_saxena
Calcite | Level 5

This solution is exactly working

Thanks a lot

MikeZdeb
Rhodochrosite | Level 12

Hi, do you really need a loop ...


data want;
set have (where=(miles le 250));
mile=miles;
run;

 

If you don't want that new variable, don't use "mile=miles"

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 5 replies
  • 1249 views
  • 0 likes
  • 4 in conversation