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.

Catch up on SAS Innovate 2026

Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.

Explore 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
  • 2274 views
  • 0 likes
  • 2 in conversation