I have a variable called GEOID10 in my SAS table which is made up of 10-11 digits. The first 4-5 digits are the State and County FIPS codes and and the last 6 digits are the Census Tract. I want to create a new variable called TACTCE only takes the last 6 digits of the GEOID10, and drops the first 4-5 digits.
Here are some examples of the GEOID10s I'm working with:
1001020700
1001020900
1001020900
1001020900
1001020900
1001021000
56035000102
56037970500
56037971600
56037971600
56037971600
56037971600
56037971600
I have tried the following codes in SAS, however it never starts at the right number.
data My.Data;
set My.Data;
TRACTCE = input(substr(GEOID10, 5), 6.);
run;
This code gave me 10207 instead of 020700 for GEOID10 1001020700.
data My.Data;
set My.Data;
TRACTCE = input(substr(GEOID10, 5, 6), 6.);
run;
This code also gave me 10207 instead of 020700 for GEOID10 1001020700.
data My.Data;
set My.Data;
TRACTCE = input(substr(GEOID10, 5), 10.);
run;
This code also gave me 1020700 instead of 020700 for GEOID10 1001020700.
data My.Data;
set My.Data;
TRACTCE = input(compress(substr(GEOID10, 5),, 'kd'), 10.);
run;
This code also gave me 1020700 instead of 020700 for GEOID10 1001020700.
data My.Data;
set My.Data;
TRACTCE = input(substr(GEOID10, 5, 6), 10.);
run;
This code also gave me 10207 instead of 020700 for GEOID10 1001020700.
data My.Data;
set My.Data;
TRACTCE = put(input(substr(GEOID10, 5, 6), 10.), z6.);
run;
This code also gave me 10207 instead of 020700 for GEOID10 1001020700.
I cannot tell what your string actually has in it from what you have shared.
But based on your first result I will assume that the first digit 1 appears in the second position. Which means that the second digit 1 is in the 5th position.
If you want to split 10 or 11 byte character strings into the last 6 and the rest then you can just use LENGTH() function to find where the last non blank character is and subtract 5.
If GEOID10 is NUMERIC then don't use character functions on it. Just use arithmetic.