BookmarkSubscribeRSS Feed
putnik
Calcite | Level 5
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
3 REPLIES 3
AndyJ
Fluorite | Level 6
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;
putnik
Calcite | Level 5
Thank you so much!
Cynthia_sas
SAS Super FREQ
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]

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 820 views
  • 0 likes
  • 3 in conversation