- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
It looks like SAS has built in function to convert from State FIPS to full state name and abbreviation to full state name but I can't find one to go from full state name to abbreviation.
data have;
input state $50.;
cards;
Alabama
Alaska
Arizona
;;;;
run;
Edit: Want:
State | Abbreviation |
Alabama | Al |
Alaska | AK |
Arizona | AZ |
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Then you just need to add another function call to the code to generate the date for the format.
Since you are now mapping character to character you can use either a format and the PUT() function or a character informat and the INPUT() function.
data fips;
fmtname='$FIPS';
length fips 8 label $2 start $20 ;
do fips=1 to 95;
start=fipnamel(fips);
if start ne 'Invalid Code' then do;
label=fipstate(fips);
output;
end;
end;
run;
proc format cntlin=fips ; run;
data test;
set fips;
statecode=put(start,$fips.);
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
There is a function to convert the code into a name like that.
So use that to make an informat you can use to convert the name to fips code.
data fips;
fmtname='FIPS';
type='I';
length label 8 start $20 ;
do label=1 to 95;
start=fipnamel(label);
if start ne 'Invalid Code' then output;
end;
run;
proc format cntlin=fips ; run;
Let's use the FIPS dataset we just made to test the new informat.
data test;
set fips;
fipscode=input(start,fips.);
run;
Results:
Obs fmtname type label start fipscode 1 FIPS I 1 Alabama 1 2 FIPS I 2 Alaska 2 3 FIPS I 4 Arizona 4 4 FIPS I 5 Arkansas 5 5 FIPS I 6 California 6 6 FIPS I 8 Colorado 8 7 FIPS I 9 Connecticut 9 8 FIPS I 10 Delaware 10 9 FIPS I 11 District of Columbia 11 10 FIPS I 12 Florida 12 ...
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Then you just need to add another function call to the code to generate the date for the format.
Since you are now mapping character to character you can use either a format and the PUT() function or a character informat and the INPUT() function.
data fips;
fmtname='$FIPS';
length fips 8 label $2 start $20 ;
do fips=1 to 95;
start=fipnamel(fips);
if start ne 'Invalid Code' then do;
label=fipstate(fips);
output;
end;
end;
run;
proc format cntlin=fips ; run;
data test;
set fips;
statecode=put(start,$fips.);
run;