Help using Base SAS procedures

How to?

Reply
New Contributor
Posts: 3

How to?

Hi, I have very limited knowledge of SAS and looking for help:
I have 3 col in table:

Year, State and Rate
2009 MA $150
2009 NH $80
2009 ME $55
2010 MA $155
2010 NH $87
2010 ME $60

I need to change the current Rates according to this statement:

if Year = 2009 and state is MA - Rate * 2
if Year = 2009 and state is NH - Rate * 3
if Year = 2009 and state is ME - Rate * 4
if Year = 2010 and state is MA - Rate * 1.5
if Year = 2010 and state is NH - Rate * 2
if Year = 2010 and state is ME - Rate * 2.5

Any ideas? Thank you
Occasional Contributor
Posts: 11

Re: How to?

data sample_data;
infile datalines;
input year state $ rate;
datalines;
2009 MA 150
2009 NH 80
2009 ME 55
2010 MA 155
2010 NH 87
2010 ME 60
;
run;

data modify;
set sample_data;

select(state);
when ('MA') do;
if year=2009 then rate=rate*2;
else if year=2010 then rate=rate*1.5;
end;
when ('NH') do;
if year=2009 then rate=rate*3;
else if year=2010 then rate=rate*2;
end;
when ('ME') do;
if year=2009 then rate=rate*3;
else if year=2010 then rate=rate*2.5;
end;
otherwise;
end;

run;
New Contributor
Posts: 3

Re: How to?

Thank you so much!
SAS Super FREQ
Posts: 8,743

Re: How to?

Hi:
As an alternative, I like the PROC FORMAT approach.
cynthia
[pre]
data rates;
infile datalines;
input year state $ rate comma8. ;
return;
datalines;
2009 MA $150
2009 NH $80
2009 ME $55
2010 MA $155
2010 NH $87
2010 ME $60
;
run;

proc format;
value $rmult '2009MA' = '2'
'2009NH' = '3'
'2009ME' = '4'
'2010MA' = '1.5'
'2010NH' = '2'
'2010ME' = '2.5';
run;

data newrate;
length testval $6;
set rates;
testval = catt(put(year,4.0),state);
mult = input(put(testval,$rmult.),best8.);
newrate = rate * mult;
run;

ods listing;
proc print data=newrate;
run;
[/pre]
Ask a Question
Discussion stats
  • 3 replies
  • 160 views
  • 0 likes
  • 3 in conversation