Date: Wed, 14 Nov 2007 17:48:05 -0500
Reply-To: Sigurd Hermansen <HERMANS1@WESTAT.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Sigurd Hermansen <HERMANS1@WESTAT.COM>
Subject: Re: Adjusting dollar amounts for inflation
In-Reply-To: <007901c82700$f77ee170$6401a8c0@HP>
Content-Type: text/plain; charset="us-ascii"
William:
Yes, but not so fast ...
The syntax of the program and result given basic test data look correct.
I'd deduct style points for several defects. For instance, the %LET
Macro statement executes before the Data step and should precede it to
emphasize that it does not repeat within the implicit Data step loop.
The Macro assignment also acts as a parameter and should not be buried
inside the program. Same for the TITLE statement. Omitting the 'data='
option in PROC PRINT in this case turns out to be risky and to no
advantage. I'd also would not award a bonus for efficiency because
writing versions 2,3, etc. of the same dataset has no purpose and slows
down program execution, or for interpretability of results due to lack
of formatting of values being display. Finally, at the semantic level,
if the 1997 to 2002 rate of inflation isn't actually 15%, the code will
not produce the correct answer even it has correct syntax and handles
assignments of values correctly. I'd look carefully at what the CPI
actually measures.
As for the program, I would make at least these changes for the sake of
good programming practice:
%LET CPI=1.15;
DATA WORK.vwDATA/view=WORK.vwDATA;
SET CLEAN_DATA;
INC_ADJ97= &CPI. * FAMINC97;
LABEL INC_ADJ97="ADJUSTED INCOME";
RUN;
/*PRINTS OUT BOTH THE ADJUSTED FAMILY INCOME FOR 1997 AND THE ACTUAL
FAMILY INCOME FOR 1997*/
TITLE "INCOME AJUSTED FOR INFLATION WITH CPI = &CPI.";
PROC PRINT data=WORK.vwDATA NOOBS;
VAR INC_ADJ97 FAMINC97;
FORMAT INC_ADJ97 FAMINC97 dollar10. ;
RUN;
TITLE;
For small datasets and simple calculations, I might also skip the view,
though it helps to learn early how to program your way around problems
of larger scale.
Best wishes for a successful programming project.
S
-----Original Message-----
From: owner-sas-l@listserv.uga.edu [mailto:owner-sas-l@listserv.uga.edu]
On Behalf Of William Elliott
Sent: Wednesday, November 14, 2007 3:57 PM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Adjusting dollar amounts for inflation
Hello, I am trying to convert 1997 dollars to 2002 dollar. Does this
code look correct.
/******** ADJUSTING FAMILY INCOME SO THAT IT IS EQUAL TO 2001 DOLLARS
******/
DATA CLEAN_DATA2; SET CLEAN_DATA;
%LET CPI=1.15;
LABEL INC_ADJ97="ADJUSTED INCOME";
INC_ADJ97=&CPI.* FAMINC97;
RUN;
/*PRINTS OUT BOTH THE ADJUSTED FAMILY INCOME FOR 1997 AND THE ACTUAL
FAMILY INCOME FOR 1997*/
PROC PRINT NOOBS;
VAR INC_ADJ97 FAMINC97;
TITLE "INCOME AJUSTED FOR INFLACTION WITH CPI = &CPI.";
RUN;
/** CREATES AN AVERAGE FOR THE TWO YEARS USING ADJUSTED FAMILY
INCOME***/
DATA CLEAN_DATA3; SET CLEAN_DATA2;
LABEL AVG_FAMINC="AVERAGE FAMILY INCOME FOR 1997 AND 2001";
AVG_FAMINC=(INC_ADJ97+FAMINC01)/2;
RUN;
/*PRINTS OUT BOTH THE AVERAGE FAMILY INCOME AND THE FAMILY INCOME FOR
2001*/
PROC PRINT NOOBS;
VAR AVG_FAMINC FAMINC01;
RUN;