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.
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;
What have you tried?
Art, CEO, AnalystFinder.com
I was trying some stuff like:
data milage;
do gallons= 1 to 10;
while(distance<250);
run;
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;
This solution is exactly working
Thanks a lot
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"
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.
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.