See if
State= stfips(statecod);
looks helpful.
Though I am wondering what "state" is represented by "AE", "AP" ???
FIPS is a US standard for certain types of coding and SAS has a number of functions that support such things.
Also this function will accept mixed case in case some of your values are "Al" instead of "AL".
The values won't exactly align but have the added value that they are a known standard and you can retrieve information from then with functions such as FIPNAME or FIPNAMEL or FIPSTATE.
What @LinusH means might look like this:
data myformat;
input start $ label $
fmtname = 'mystates';
type = 'C';
datalines;
AE 1
AK 2
AL 3
;
run;
You can join along start, or use it as a cntlin for proc format; note how the datalines reduce your typing effort.
I mdofied my previous codes and divided the states into 4 Regions, but its generating a character missing values.
any inputs will be appreciated and also can i change the new variable STATECOD_1 to Numeric Type.
Thanks kindly
data sas_pr.merge_4;
set sas_pr.merge_3;
length STATECOD_1 $ 14;
if STATECOD = in('CT', 'ME','MA','NH','RI','VT','NJ','NY','PA')
THEN STATECOD_1 = 'Region_1';
if STATECOD = in('IL','IN','MI','OH','WI','IA','KS','MN','MO','NE','ND','SD')
THEN STATECOD_1 = 'Region_2';
if STATECOD = in('DE','FL','GA','MD','NC','SC','VA','DC','WV','AL','KY','MS','TN','AR','LA','OK','TX')
THEN STATECOD_1 = 'Region_3';
if STATECOD = in('AZ','CO','ID','MT','NV','NM','UT','WY','AK','CA','HI','OR','WA')
THEN STATECOD_1 = 'Region_4';
RUN;
There should be no equal sign between STATECOD and IN(...).
if STATECOD IN(....) then ....;
@azhar7860 wrote:
I mdofied my previous codes and divided the states into 4 Regions, but its generating a character missing values.
any inputs will be appreciated and also can i change the new variable STATECOD_1 to Numeric Type.
Thanks kindly
data sas_pr.merge_4;
set sas_pr.merge_3;
length STATECOD_1 $ 14;
if STATECOD = in('CT', 'ME','MA','NH','RI','VT','NJ','NY','PA')
THEN STATECOD_1 = 'Region_1';
if STATECOD = in('IL','IN','MI','OH','WI','IA','KS','MN','MO','NE','ND','SD')
THEN STATECOD_1 = 'Region_2';
if STATECOD = in('DE','FL','GA','MD','NC','SC','VA','DC','WV','AL','KY','MS','TN','AR','LA','OK','TX')
THEN STATECOD_1 = 'Region_3';
if STATECOD = in('AZ','CO','ID','MT','NV','NM','UT','WY','AK','CA','HI','OR','WA')
THEN STATECOD_1 = 'Region_4';
RUN;
I notice AE AP VI PR are no longer involved ...
@azhar7860 wrote:
I mdofied my previous codes and divided the states into 4 Regions, but its generating a character missing values.
any inputs will be appreciated and also can i change the new variable STATECOD_1 to Numeric Type.
Thanks kindly
data sas_pr.merge_4;
set sas_pr.merge_3;
length STATECOD_1 $ 14;
if STATECOD = in('CT', 'ME','MA','NH','RI','VT','NJ','NY','PA')
THEN STATECOD_1 = 'Region_1';
if STATECOD = in('IL','IN','MI','OH','WI','IA','KS','MN','MO','NE','ND','SD')
THEN STATECOD_1 = 'Region_2';
if STATECOD = in('DE','FL','GA','MD','NC','SC','VA','DC','WV','AL','KY','MS','TN','AR','LA','OK','TX')
THEN STATECOD_1 = 'Region_3';
if STATECOD = in('AZ','CO','ID','MT','NV','NM','UT','WY','AK','CA','HI','OR','WA')
THEN STATECOD_1 = 'Region_4';
RUN;
Once again, create a lookup dataset and a format from that, and the cards section will look like
cards;
CT Region_1
ME Region_1
.....
IL Region_2
IN Region_2
and so on.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.