BookmarkSubscribeRSS Feed
coder1234
Obsidian | Level 7

Modify the DO statement to produce the following results. The DO statement will now be based on a list of values instead of a value that is incremented.

An alternate solution instead of: 

Spoiler
typing out the Year 1, Year 2... manually which the solution suggests, could use 

YearZ=cat('Year ', Year);

data IncMPG;
    set sashelp.cars;
    MPG=mean(MPG_City, MPG_Highway);

DO Year = 1 to 5; 
MPG=sum(MPG*1.03);
YearZ=cat('Year ', Year);
output;
end;
run;

title 'Projected Fuel Efficiency with 3% Annual Increase';
proc print data=IncMPG;
    var Make Model YearZ MPG;
	format MPG 4.1;
run;
title;
Which gives the same end result. 

 

1 REPLY 1
OleSteen
SAS Employee

You are asked to change from a DO-loop with incremented numeric year, to create a character value like "Year 1", "Year 2" etc.

This can be done with a DO-loop like:

 

Do Year = "Year 1", "Year 2" etc.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

LIBNAME 101

Follow along as SAS technical trainer Dominique Weatherspoon expertly answers all your questions about SAS Libraries.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 1177 views
  • 0 likes
  • 2 in conversation