Hi All,
I have Data set below :
Sate | Rate |
Alabama | 0.0400 |
Alaska | 0.0000 |
Arizona | 0.0560 |
Arkansas | 0.0650 |
California (b) | 0.0725 |
Colorado | 0.0290 |
Connecticut | 0.0635 |
Delaware | 0.0000 |
District of Columbia | 0.0575 |
Florida | 0.0600 |
Georgia | 0.0400 |
Hawaii (c) | 0.0400 |
Idaho | 0.0600 |
Illinois | 0.0625 |
Indiana | 0.0700 |
Iowa | 0.0600 |
Kansas | 0.0650 |
Kentucky | 0.0600 |
Louisiana | 0.0445 |
Maine | 0.0550 |
Maryland | 0.0600 |
Massachusetts | 0.0625 |
Michigan | 0.0600 |
Minnesota | 0.0688 |
Mississippi | 0.0700 |
Missouri | 0.0423 |
Montana (d) | 0.0000 |
I need output as :
State | Compare_with | Difference Vector |
Alabama | Alaska | 0.0400 |
Alabama | Arizona | -0.0160 |
Alabama | Arizona | -0.0160 |
Alabama | Arkansas | -0.0250 |
Alabama | California (b) | -0.0325 |
Alabama | Colorado | 0.0110 |
Alabama | Connecticut | -0.0235 |
Alabama | Delaware | 0.0400 |
Like this I need to compare with each state with corresponding difference Vector.
Please help me!
Thanks In advance!
data have;
input State :$30. Rate;
infile datalines dlm=',';
datalines;
Alabama,0.0400
Alaska,0.0000
Arizona,0.0560
Arkansas,0.0650
California (b),0.0725
Colorado,0.0290
Connecticut,0.0635
Delaware,0.0000
District of Columbia,0.0575
Florida,0.0600
Georgia,0.0400
Hawaii (c),0.0400
Idaho,0.0600
Illinois,0.0625
Indiana,0.0700
Iowa,0.0600
Kansas,0.0650
Kentucky,0.0600
Louisiana,0.0445
Maine,0.0550
Maryland,0.0600
Massachusetts,0.0625
Michigan,0.0600
Minnesota,0.0688
Mississippi,0.0700
Missouri,0.0423
Montana (d),0.0000
;
data want;
set have;
do i=1 to n;
set have(rename=(Rate=_Rate State=Compare_with)) point=i nobs=n;
Diff=Rate-_Rate;
if State ne Compare_with then output;
end;
keep State Compare_with Diff;
run;
data have;
input State :$30. Rate;
infile datalines dlm=',';
datalines;
Alabama,0.0400
Alaska,0.0000
Arizona,0.0560
Arkansas,0.0650
California (b),0.0725
Colorado,0.0290
Connecticut,0.0635
Delaware,0.0000
District of Columbia,0.0575
Florida,0.0600
Georgia,0.0400
Hawaii (c),0.0400
Idaho,0.0600
Illinois,0.0625
Indiana,0.0700
Iowa,0.0600
Kansas,0.0650
Kentucky,0.0600
Louisiana,0.0445
Maine,0.0550
Maryland,0.0600
Massachusetts,0.0625
Michigan,0.0600
Minnesota,0.0688
Mississippi,0.0700
Missouri,0.0423
Montana (d),0.0000
;
data want;
set have;
do i=1 to n;
set have(rename=(Rate=_Rate State=Compare_with)) point=i nobs=n;
Diff=Rate-_Rate;
if State ne Compare_with then output;
end;
keep State Compare_with Diff;
run;
Wow! That's so quick.. Perfect Solution!
Thank you
data want;
if _n_=1 then set have(obs=1 rename=(rate=original_rate));
set have(firstobs=2 rename=(state=compare_with));
run;
I didn't add in code to do the subtraction, I figure you can do that yourself (and I'm lazy).
Thanks a lot for your quick answer. this is perfect!
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.